Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error received Bad JSON escape sequence [duplicate]

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

like image 500
Cainnech Avatar asked Aug 21 '18 12:08

Cainnech


1 Answers

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\"}]
like image 88
seebiscuit Avatar answered Nov 03 '22 22:11

seebiscuit