SyntaxError: Bad control character in string literal in JSON at position N means there is a raw, unescaped control character — a tab, newline, carriage return, or any character in the range U+0000–U+001F — sitting inside a JSON string. The JSON specification forbids them. This article explains why, where they come from, and how to get rid of them.
Which string-error am I getting?
- Bad control character — a raw tab/newline/null byte sits inside a string without escaping.
- Bad escaped character — a
\is followed by something JSON doesn't allow (e.g.\x, Windows paths). - Unterminated string — a string was opened with
"but never closed.
What Is a Control Character?
The first 32 Unicode code points (U+0000 through U+001F) are control characters — invisible formatting codes inherited from teletype machines. Some familiar ones:
| Code point | Name | JSON escape |
|---|---|---|
U+0000 | Null | |