j Ko j Ko - 6 days ago 7
Javascript Question

JSON.parse produces a SyntaxError

Inputting this:

JSON.parse("{list : []}");


produces this in the console:

VM9793:1 Uncaught SyntaxError: Unexpected token l in JSON at position 1
at JSON.parse (<anonymous>)
at <anonymous>:1:6


enter image description here

Answer

JSON requires object keys to be stings, so it needs to be:

JSON.parse('{"list" : []}');