Tuesday, July 12, 2016

JSON: Invalid UTF-8 middle byte

Assume you have the following JSON:
 
{
     "myObject" :
{
"name" : "resumé"
}
}
 
If you run this with your favorite JSON parser, you may get the following error:

[{"message":"Invalid UTF-8 middle byte 0x65 at [line:.., column:..]","errorCode":"JSON_PARSER_ERROR"}]

To solve this, you will either need to update your parser to only accept UTF (8, 16, or 32), or escape the especial characters (i.e. \u00E9 for é)

As a test, you can try this:

{
     "myObject" :
{
"name" : "resum\u00E9"
}
}

No comments:

Post a Comment