formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

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.

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.