Bad control character in string literal in JSON

Bad control character in string literal in JSON at position 12 (line 1 column 13)

Control characters are non-printable characters with ASCII codes 0–31, including raw newlines (\n, U+000A), carriage returns (\r, U+000D), tabs (\t, U+0009), and null bytes (U+0000). JSON requires these to be escaped as \n, \r, \t, \u0000, etc. when they appear inside a string value. If you embed the raw binary character directly in the JSON text, the parser rejects it. This is most common when JSON is assembled by string concatenation from user input or file content.

Raw newline inside a string value

A literal line break inside a JSON string is illegal. The string must use the \n escape sequence instead. This frequently happens when multiline text is inserted into JSON via template strings or read from a file.

Invalid

{"description": "line one
line two"}

Valid

{"description": "line one\nline two"}

Raw tab character inside a string

Tabs that are not escape sequences are control characters (U+0009). They often sneak in when content is pasted from a spreadsheet or TSV file.

Invalid

{"tsv": "col1	col2"}

Valid

{"tsv": "col1\tcol2"}

Null byte in binary data

If binary data is converted to a string and embedded in JSON without escaping, any null bytes (U+0000) become bad control characters. Always base64-encode binary data before placing it in a JSON string.

Invalid

{"data": "prefixsuffix"}

Valid

{"data": "cHJlZml4c3VmZml4"}  // base64 encoded

Building JSON by string concatenation

Using string concatenation or template literals to build JSON instead of JSON.stringify is the root cause in most real-world occurrences. JSON.stringify handles all escaping automatically.

Invalid

const text = userInput  // may contain newlines
const json = `{"text": "${text}"}`  // unescaped control chars

Valid

const json = JSON.stringify({ text: userInput })  // safe

Fix this error in seconds

Paste your JSON in the free validator to find the exact line and column where the error occurs.

Open JSON Validator →

Frequently Asked Questions

How do I safely include multiline text in JSON?

Always use JSON.stringify() to serialize any string that may contain special characters. It automatically escapes newlines, tabs, quotes, and all other control characters. If you must write the JSON by hand, replace literal newlines with \n, tabs with \t, and carriage returns with \r.

Can I detect control characters before parsing?

Yes: /[\x00-\x1F]/.test(jsonString) returns true if any raw control characters are present. This is a useful pre-validation step in ingestion pipelines. Note that \x09 (tab), \x0A (newline), and \x0D (carriage return) are the most common offenders.

More JSON errors