"Bad control character in string literal" Error, Explained
JSON string values can't contain a literal newline, tab, or other control character — they have to be escaped. This is a stricter rule than most people expect coming from other languages.
What triggers it
{
"note": "line one
line two"
}
That raw newline inside the string breaks parsing with something like Bad control character in string literal in JSON at position 11. The same happens with a literal tab character, or with control characters copy-pasted in from another source (e.g. terminal output with embedded control codes).
Why JSON requires this
RFC 8259 requires control characters (U+0000 through U+001F) inside a string to be escaped — a newline must be written as \n, a tab as \t, and so on. This keeps JSON text unambiguous and safe to embed in other formats without a raw byte silently breaking line-based tooling (like log parsers) downstream.
How to fix it
- If you're generating JSON programmatically, use a real serializer (
JSON.stringify,json.dumps) — it escapes control characters automatically. This error almost always means JSON was built by hand or via string concatenation. - If you're hand-editing, replace the raw newline/tab inside the string with
\n/\t. - If the JSON came from somewhere else and you just need it fixed, paste it into JSON Repair.