JSON.parse UTF-8 string

21,656

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

Share:
21,656
Karim Benhmida
Author by

Karim Benhmida

Updated on June 09, 2020

Comments

  • Karim Benhmida
    Karim Benhmida almost 4 years

    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?