Cryonel

"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

Related Tools