Answer the question
In order to leave comments, you need to log in
How can I parse such a string?
I have a similar string "{one:{hello:[{two:three}]}}"
How can I turn it into a JSON object if the function JSON.parse()
throws an error
SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
Answer the question
In order to leave comments, you need to log in
You need to use the JSON5 decoder
https://json5.org/
Oops
, didn't notice you didn't have three in quotes. Then it won't fly.
Then you can try like this:
var myjson = unquotedJson.replace(/(['"])?([a-zA-Z0-9]+)(['"])?/g, '"$2"');
JSON.parse(myjson)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question