Bad control character in string literal in JSON

JSON strings may not contain raw control characters, the invisible characters U+0000 to U+001F. That includes the newline, carriage return and tab you get by pressing Enter or Tab. Inside a string they must be written as escapes: \n, \r, \t or \u00XX. The error points at the control character itself, which is often invisible in an editor.

Seen as:

  • SyntaxError: Bad control character in string literal in JSON at position 61 (line 3 column 32)
  • SyntaxError: JSON.parse: bad control character in string literal at line 3 column 32 of the JSON data
  • json.decoder.JSONDecodeError: Invalid control character at: line 3 column 32 (char 61)
  • invalid character '\n' in string literal

Input

Settings

History

Load from URL

Common causes

1. A multi-line text pasted into a string

Pressing Enter inside a string, or pasting a paragraph, inserts a real line break. Replace each one with \n.

Before
{"body": "Fixed the login bug.
Improved search speed."}
After
{"body": "Fixed the login bug.\nImproved search speed."}

2. A tab copied from a spreadsheet or terminal

Cells copied from Excel or Google Sheets are separated by tab characters. A tab looks like spaces but is a control character; write it as \t.

Before
{"row": "SKU-1	Keyboard	129.90"}
After
{"row": "SKU-1\tKeyboard\t129.90"}

3. JSON assembled with string templates

Inserting user input into a JSON template copies its line breaks and tabs verbatim. A serializer escapes them for you.

Before
const body = `{"comment": "${comment}"}`;
After
const body = JSON.stringify({ comment });

4. Invisible characters from binary data or old systems

NUL bytes, form feeds and vertical tabs come from binary data, legacy exports or Word documents. Remove them, or keep them as \u0000-style escapes if they matter.

Before
{"code": "AB"}
After
{"code": "A\u000bB"}

Frequently asked questions

Which characters count as control characters?

The 32 characters from U+0000 to U+001F, including newline (U+000A), carriage return (U+000D) and tab (U+0009). DEL (U+007F) and non-breaking spaces are allowed in JSON strings.

Can Python accept raw newlines in strings?

Yes: json.loads(text, strict=False) allows control characters inside strings. Use it only to recover data you cannot fix at the source, and write valid JSON back out.

Why can I not see the bad character?

Control characters have no visible glyph, and tabs look like spaces. PasteKit names the exact character, for example U+0009, and highlights its position.

Related