Invalid control character with Python json.loads
Solution 1:
The control character can be allowed inside a string as follows,
json_str = json.loads(jsonString, strict=False)
You can find this in the docs for python 2, or the docs for python 3
If strict is false (
True
is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0–31 range, including'\t'
(tab),'\n'
,'\r'
and'\0'
.
Solution 2:
There is no error in your json text.
You can get the error if you copy-paste the string into your Python source code as a string literal. In that case \n
is interpreted as a single character (newline). You can fix it by using raw-string literals instead (r''
, Use triple-quotes r'''..'''
to avoid escaping "'
quotes inside the string literal).