Hirad Roshandel
Hirad Roshandel

Reputation: 2187

converting String to Json - javascript

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

Upvotes: 0

Views: 110

Answers (1)

Sanjay Sahani
Sanjay Sahani

Reputation: 580

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

"{"0":[1],"2":[1]}"

Upvotes: 2

Related Questions