skb
skb

Reputation: 31164

Why is JSON.Parse saying "invalid character"?

I have a piece of JS running in IE with the following line:

var data = JSON.parse("{ skill: 'SK_AUTO_DEV_TEST', kind: 'IS_REQUIRED' }");

Can anyone tell me what's wrong with this?

Upvotes: 6

Views: 52758

Answers (2)

epascarello
epascarello

Reputation: 207557

Because that is not Valid JSON – you need quotes around the property names.

JSON.parse('{ "skill": "SK_AUTO_DEV_TEST", "kind": "IS_REQUIRED" }');

Upvotes: 16

Jack A.
Jack A.

Reputation: 4453

To elaborate on epascarello's answer, please refer to json.org. Note in the first diagram that the name in the name/value pair is defined as "string". Then note in the diagram that defines "string" that it must begin and end with double-quote. Also note that this applies to both name and value.

Upvotes: 3

Related Questions