Got it figured out with a custom func after a long tryout, not a straight forward, but works as needed. The original problem was the input is received as a buffer from zmq broker and there's that weird format of data from msg.toString()
Steps:
Used a regex to segregate the object data,
replace the regex match with template string,
split it, replace the 'made' array and return it.
export const parseTheCrapOutOfThatDamnString = (paramString: string) => { const regEx = RegExp("(?<={)(.*)(?=})") //(?<={)(.*)(?=}) //https://regexr.com/2tr5t if(regEx.test(paramString)) { var theMatch:string = `${_.head(paramString.match(regEx))}` || "" //;console.log(`\n${theMatch}\n`) var paramsArray = _.replace(paramString, theMatch, "replaceable").split(',') //;console.log(paramString) return paramsArray[paramsArray.indexOf('{replaceable}')] = JSON.parse(`{${theMatch}}`) }else { return JSON.parse("["+paramString+"]") } }
the call,
const msgs = 'string_no_quotes,"string-with@}-weirdchars",{"ckey":null,"email":"user@gmail.com","pass":"password","name":{"firstName":"User","middleName":"","lastName":"Name"},"address":{"street": "test street", "country":"some country", "zip": "639821"},"status":1},opt-data'
console.log(parseTheCrapOutOfThatDamnString(msgs))
the final output:
["string_no_quotes", "string-with@}-weirdchars", {
"ckey": null,
"email": "user@gmail.com",
"pass": "password",
"name": {
"firstName": "User",
"middleName": "",
"lastName": "Name"
},
"address": {
"street": "test street",
"country": "some country",
"zip": "639821"
},
"status": 1
}, "opt-data"]
here it is Typescript play