7

I am using simplejson to decode the following json string.

Here is a demo written in Python:

from simplejson import loads

loads("""["\s"]""")

The decoder will throw:

JSONDecodeError: Invalid \escape

How to cope with this? The expected output is:

["\\s"]
xiaohan2012
  • 9,870
  • 23
  • 67
  • 101
  • Almost a duplicate of [python - json reading error json.decoder.JSONDecodeError: Invalid \escape - Stack Overflow](https://stackoverflow.com/questions/44687525/json-reading-error-json-decoder-jsondecodeerror-invalid-escape) – user202729 Feb 17 '21 at 11:55

1 Answers1

8

"\s" is not a valid JSON escape string.

According to json.org, only the following escape are valid

  • \"
  • \\
  • /
  • \b
  • \f
  • \n
  • \r
  • \t
  • \u four-hex-digits
Demon
  • 216
  • 2
  • 2