I have a bit of JSON coming from a mock that needs to de deserialized into an object. The JSON itself is perfectly valid. It has been validated by multiple services, and they all say it looks legit.

However, I consequently get

System.JSONException: Unexpected character ('\' (code 92)): was expecting double-quote to start field name at [line:1, column:3]

Which is odd, because there is not even a single backslash character in the file.

Then, when I fold the JSON into 'compact' form, removing all spaces, tabs, indentation etc, it suddenly works.

Any clues? Anybody had something similar before?

  • Can you post sample json response. Also validate json response which you get. – Reshma Dec 17 '18 at 9:58
  • Sorry can't post it, it is a huge file and contains confidential details. I was just wondering if it rings a bell with someone who had experienced an identical situation. And yes, as mentiond, I validated the JSON multiple times using different linters/validators. – Willem Mulder Dec 17 '18 at 10:02
  • Found similar issue here – Reshma Dec 17 '18 at 10:05
  • Sounds like an encoding issue or something. Since it's at 1:3, maybe you could just give us like... the first 5-6 characters of your JSON? Or just look for anything unusual around that location. – sfdcfox Dec 17 '18 at 10:58
  • leading line break? – cropredy Dec 18 '18 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.