j Ko j Ko - 1 year ago 139
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 Source

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

JSON.parse('{"list" : []}');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download