1

In this fiddle I'm just trying to return true : http://jsfiddle.net/WCFtp/ for jQuery key 'saved'

Why do I receive the error "Uncaught SyntaxError: Unexpected token s"

Code below :

        var test = "{saved: true}";
        var jsonSaveResponse = jQuery.parseJSON(test);
        alert(jsonSaveResponse.saved);    

3 Answers 3

3

Should be var test = '{"saved": true}';.

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

Comments

3

Your JSON isn't valid. Object attribute names must be quoted:

var test = '{"saved": true}';

Keep in mind, JSON is a subset of valid Javascript syntax. Lots of valid Javascript is invalid JSON.

Comments

1

See the parseJSON docs.

Passing in a malformed JSON string may result in an exception being thrown. For example, the following are all malformed JSON strings:

{test: 1} (test does not have double quotes around it).

{'test': 1} ('test' is using single quotes instead of double quotes).

You'll want to use this instead:

var test = "{\"saved\": true}";

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.