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\"}]
Share:
13,145

Related videos on Youtube

Cainnech
Author by

Cainnech

Updated on June 04, 2022

Comments

  • Cainnech
    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
      mjwills over 5 years
      JsonLint complains about the string {"command":"cue","channel":1,"uid":"aesd-deaf","type":"stand‌​ard","waitforexecute‌​":true,"duration":0,‌​"scene":[{"name":"Sc‌​ene1","fields":[{"Qu‌​ad1":"F:\TestFolder\‌​mill.jpg"}]}]} (which is your string) - there should be extra \ characters in the file path - \\ should be \\\\.
    • Patrick Hofman
      Patrick Hofman over 5 years
  • seebiscuit
    seebiscuit over 5 years
    So...negative votes for a correct answer? At least, I hope it helped, Cainnech.
  • Cainnech
    Cainnech over 5 years
    You are correct, that was the issue. I wasn't taking into consideration that the \ had to be double-escaped.