[Solved] JSON check syntax error: json.decoder.JSONDecodeError: Invalid control character at: line 1 column

Problem details: json.decoder.jsondecodeerror: invalid control character at: Line 1 column 5515 (char 5514)

Reason: STR contains \t \n and other contents. Note that it is not the characters “\t” and “\n”. Therefore, an error is reported when checking the syntax of JSON.

If strict is false (the default is true), control characters are allowed in the string.

Solution 1: add the strict = false parameter

json.loads(f_str, strict=False)

Solution 2: replace \ t \ n with

f_str=f_str.replace('\n', ' ')
f_str=f_str.replace('\t', ' ')

Done!

Similar Posts: