0

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

4
  • 2
    Because that's not JSON. Commented Aug 30, 2014 at 1:01
  • en.wikipedia.org/wiki/JSON Commented Aug 30, 2014 at 1:03
  • 3
    JSON does not accept simple quotes as string delimiters, use double quotes instead Commented Aug 30, 2014 at 1:05
  • Could it be that you are trying to convert a string to an object? Because that's what JSON.parse does: It converts JSON to a JavaScript value. It does not convert to JSON, that's what JSON.stringify does. JSON is a language-independent, textual data exchange format, it's not a JavaScript value / data type. Commented Aug 30, 2014 at 3:10

1 Answer 1

2

You need to wrap it with curly braces to make it work. ex. This will work fine.

"{"0":[1],"2":[1]}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.