JSON.parse UTF-8 string

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?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply