Since the response is not a JSON and we don't exactly know the specification of the API response (is there a spec for this kind of return?), you can try to parse it with a dirty hack.
const str = "[{oId=151, oName=store city}, {oId=247, oName=customer city}]";
const result = JSON.parse(
str.replaceAll(", ", ",")
.replace(/([^,{]+)?=([^,}]+)?/gi, `"$1":"$2"`) // Sorry.
);
Result will return:
[
{
"oId": 151,
"oName": "store city"
},
{
"oId": 247,
"oName": "customer city"
}
]
Please note that it will fix your actual issue, still:
- It will not work in all cases (if there is coma in string or double quote somewhere.
- I strongly advise that you contact the API designer since they created a super exotic format that does not scale at all.
,in middle of string looks like). OR contact API provider and ask to return proper JSON response