Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON decode issue

I'm trying to decode JSON output of a Java program (jackson) and having some issues. The cause of the problem is the following snippet:

{
    "description": "... lives\uMOVE™ OFFERS ",
}

Which causes ValueError: Invalid \uXXXX escape.

Any ideas on how to fix this?

EDIT: The output is from an Avro file, the Avro package uses jackson to emit records as JSON.
EDIT2: After poking about in the source files, it might be the case that the JSON is constructed manually (sorry jackson).

like image 554
lazy1 Avatar asked Sep 04 '25 03:09

lazy1


2 Answers

What's the original string supposed to look like? \uXXXX is a unicode escape sequence, so it's interpreting \uMOVE as a single character, but it's not a valid unicode value. JSON is always assumed to be unicode, so you'll likely need to fix the string in the originating app

like image 185
dfb Avatar answered Sep 05 '25 19:09

dfb


Try quoting the \u like this:

{
    "description": "... lives\\uMOVE™ OFFERS ", 
}
like image 28
Rich Avatar answered Sep 05 '25 19:09

Rich