j Ko j Ko - 4 months ago 70
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" : []}');