3

Why dosen't JSON.parse parse this:

{
    "things1": "[{\"stuff1\":\"data1\"}]"
}

When I enter this

JSON.parse('{ "things1": "[{\"stuff1\":\"data1\"}]" }')

I get:

Uncaught SyntaxError: Unexpected token s

It seems "[{\"stuff1\":\"data1\"}]" is properly escaped.

1
  • Well, it's not a valid json. things1 attribute points to a string that starts with [{ and interrupts then. Where did you get it from? Commented Apr 6, 2015 at 1:41

1 Answer 1

3

You are having escaping issues, specifically because you have nested strings. You need to double escape the \" bits using \\".

Edited: Meant to add a sample.

JSON.parse('{ "things1": "[{\\"stuff1\\":\\"data1\\"}]" }');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.