SyntaxError: Bad control character in string literal in JSON
A JSON string contains a raw control character (newline, tab, carriage return, or a byte below 0x20) that must be escaped. The fix is to replace the literal character with its escape sequence — \n, \t, \r — or let JSON.stringify() do it for you.
Runs entirely in your browser — your JSON is never uploaded to a server. No ads injected into the output, no sign-up, and the repair logic is tuned for this exact error rather than generic pretty-printing.
How to fix "Bad control character in string literal in JSON"
- Find the control character. A raw newline, tab, or other control byte (char code below 0x20) appears inside a string. JSON requires these to be escaped.
- Escape them. Replace literal newlines with \n, tabs with \t, and carriage returns with \r inside the string value. The tool above does this automatically on Repair.
- Fix at the source. If you build the JSON in code, use a serializer (JSON.stringify / json.dumps) instead of string concatenation so control characters are escaped for you.
What the error means
The JSON spec forbids unescaped control characters (U+0000 through U+001F) inside string literals. A real tab, newline, or carriage return pasted into the value triggers "Bad control character in string literal".
Where it comes from
Usually you concatenated text that contained line breaks, or read a file with Windows \r\n endings and dropped it straight into a JSON string. The characters are invisible in most editors, which is why the bug is hard to spot.
Fix it
Do not hand-build JSON. Build a real object and call JSON.stringify(obj) — it escapes control characters automatically. If you must patch existing text, replace raw newlines with \n, tabs with \t, and carriage returns with \r. Paste the payload above and hit Repair — it escapes the offending control characters in place so the string parses.
FAQ
How do I find an invisible control character?
Enable 'show whitespace' in your editor, or run the text through the tool above — it flags and escapes the byte that breaks parsing.
Python raises 'Invalid control character at' — is that the same?
Yes, it is Python's wording for the identical problem. The fix is the same: escape the control character or set strict=False in json.loads as a last resort.
Why does stringify fix it but my manual string does not?
JSON.stringify walks each character and emits the proper escape sequence; a hand-typed string keeps the raw bytes, which the parser rejects.