Fix "Bad control character in string literal"
JavaScript / Python ยท JSON error
Opens the editor with a broken example loaded and repaired, entirely in your browser โ nothing is uploaded.
What causes it
Inside a JSON string, control characters (character codes below U+0020) โ literal newlines, tabs, carriage returns, and similar โ are not allowed to appear raw. They must be written as escape sequences: \n for newline, \t for tab, \r for carriage return.
This usually happens when multi-line text (a log message, a code snippet, a description) is dropped straight into a JSON string without escaping, or when a value was built by string concatenation instead of a real serializer.
How to fix it
- Find the string that spans a real line break or contains a literal tab.
- Replace the raw newline with \n and the raw tab with \t inside the string.
- Better: build JSON with a real serializer (JSON.stringify / json.dumps), which escapes automatically.
- Paste the text into JSON Wallet and use Repair to escape stray control characters for you.
Before and after
Broken:
{
"message": "line one
line two"
}Fixed:
{
"message": "line one\nline two"
}Want to fix your own JSON instead of the example? Open the editor, paste it in, and click Repair โ it runs entirely in your browser.
Frequently asked questions
Which characters have to be escaped in a JSON string?
The double quote, the backslash, and all control characters below U+0020 โ most commonly newline (\n), carriage return (\r) and tab (\t).
How do I avoid this when generating JSON?
Never build JSON by hand with string concatenation. Use your language's serializer โ JSON.stringify() or json.dumps() โ which escapes every special character correctly.
Related JSON errors
Fix "Unexpected token in JSON at position N"
The most common JSON.parse() error. It means the parser hit a character it did not expect โ usually HTML, an already-parsed object, or a stray token.
Fix JSON With Single Quotes
JSON only allows double quotes. Single quotes โ common when copying object literals from JavaScript or Python โ are rejected by every strict parser.
For a full reference of JSON mistakes, read Common JSON errors and how to fix them.