Error received Bad JSON escape sequence
13,145
Like the error says, the problem happens inside the array for the fields
property:
[{\"Quad1\":\"F:\\TestFolder\\mill.jpg\"}]
Imagine what this looks like, once parsed:
[{"Quad1": "F:\TestFolder\mill.jpg"}]
The JSON parser doesn't recognize the escape sequence \T
, which is not the same as \t
.
To fix is simply double escape all the \
characters. So that section would look like:
\"fields\": [{\"Quad1\":\"F:\\\\TestFolder\\\\mill.jpg\"}]
Related videos on Youtube
Author by
Cainnech
Updated on June 04, 2022Comments
-
Cainnech almost 2 years
I'm currently testing an application but it's throwing a Bad JSON Escape Sequence at me, however I don't see the problem...
I'm probably overlooking something so a fresh pair of eyes might be useful.
messageContents = "{\"command\":\"cue\",\"channel\":1,\"uid\":\"aesd-deaf\",\"type\":\"standard\",\"waitforexecute\":true,\"duration\":0,\"scene\":[{\"name\":\"Scene1\",\"fields\":[{\"Quad1\":\"F:\\TestFolder\\mill.jpg\"}]}]}";
And the error I'm getting is
{"Bad JSON escape sequence: \\T. Path 'scene[0].fields[0].Quad1', line 1, position 150."}
Can anyone spot the mistake? Thanks, Kenneth
-
mjwills over 5 yearsJsonLint complains about the string
{"command":"cue","channel":1,"uid":"aesd-deaf","type":"standard","waitforexecute":true,"duration":0,"scene":[{"name":"Scene1","fields":[{"Quad1":"F:\TestFolder\mill.jpg"}]}]}
(which is your string) - there should be extra \ characters in the file path - \\ should be \\\\. -
Patrick Hofman over 5 yearsDuplicate of stackoverflow.com/q/41646878/993547.
-
-
seebiscuit over 5 yearsSo...negative votes for a correct answer? At least, I hope it helped, Cainnech.
-
Cainnech over 5 yearsYou are correct, that was the issue. I wasn't taking into consideration that the \ had to be double-escaped.