I have this variable which is json-like string, error appear while parse to a object
"SyntaxError: JSON.parse: expected ',' or '}' after property value in object"
Code:
var obj = JSON.parse('{"data":[{"from":"{\"category\":\"Bank/financial institution\"}"}],"statusCode":200}');
Seems the function not available for nested "{\"category\":\"Bank/financial institution\"}", replace with simple text (e.g. “123”) would be fine, is there any way to handle such cases?
Thanks.
Your string is indeed malformed.
You either want:
…(e.g., without quotes around the value of
fromand without backslashes) which when deserialized results in an object with a property calleddatawhich is an array, which has as its first entry an object with a property calledfromwhich is an object: Live Example | Sourceor
…(e.g., keeping the quotes around the value for
fromand making sure the backslashes appear in the JSON, which means escaping them) which is the same until you get tofrom, which is a string: Live Example | Source