Hi I'm trying to convert a string like this:
{'2': [1], '0': [1]}
to json using JSON.parse in javascript but it keeps saying
Uncaught SyntaxError: Unexpected token '
can anyone help me with this, thanks
asked Aug 30, 2014 at 0:59
Hirad Roshandel
2,1876 gold badges43 silver badges66 bronze badges
1 Answer 1
You need to wrap it with curly braces to make it work. ex. This will work fine.
"{"0":[1],"2":[1]}"
answered Aug 30, 2014 at 1:06
Sanjay Sahani
5805 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
JSON.parsedoes: It converts JSON to a JavaScript value. It does not convert to JSON, that's whatJSON.stringifydoes. JSON is a language-independent, textual data exchange format, it's not a JavaScript value / data type.