j Ko j Ko - 5 months ago 79
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


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

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