8

I'm trying to parse a UTF-8 encoded string, but JSON.parse is choking on this line:

undefined:306 , "o": { "type": "uri", "value": "http://got.dbpedia.org/resource/\U00010331\ ^ SyntaxError: Unexpected token U

this is the line I use:

var object = JSON.parse(data);

I've also tried with this line, but no success:

var object = JSON.parse(data.toString('utf8'));

Any idea?

1 Answer 1

8

In a JSON string a \ character may not be followed by an uppercase U character. Your JSON is invalid. You need a lowercase u instead and should fix whatever is outputting the invalid JSON.

JSON Strings

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

1 Comment

Ok, thanks for the clarification. The problem is I get the JSON from an API I'm not the owner of, so I'll have to correct the JSON before trying to parse it.

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.