JSON WalletPrivacy-first JSON & API workspace

Fix "Bad control character in string literal"

JavaScript / Python ยท JSON error

โ† All tools

Bad control character in string literal in JSON at position NSyntaxError: Bad control character in string literalInvalid control character at: line N column N (char N)

Opens the editor with a broken example loaded and repaired, entirely in your browser โ€” nothing is uploaded.

What causes it

Inside a JSON string, control characters (character codes below U+0020) โ€” literal newlines, tabs, carriage returns, and similar โ€” are not allowed to appear raw. They must be written as escape sequences: \n for newline, \t for tab, \r for carriage return.

This usually happens when multi-line text (a log message, a code snippet, a description) is dropped straight into a JSON string without escaping, or when a value was built by string concatenation instead of a real serializer.

How to fix it

  1. Find the string that spans a real line break or contains a literal tab.
  2. Replace the raw newline with \n and the raw tab with \t inside the string.
  3. Better: build JSON with a real serializer (JSON.stringify / json.dumps), which escapes automatically.
  4. Paste the text into JSON Wallet and use Repair to escape stray control characters for you.

Before and after

Broken:

{
  "message": "line one
line two"
}

Fixed:

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

Want to fix your own JSON instead of the example? Open the editor, paste it in, and click Repair โ€” it runs entirely in your browser.

Frequently asked questions

Which characters have to be escaped in a JSON string?

The double quote, the backslash, and all control characters below U+0020 โ€” most commonly newline (\n), carriage return (\r) and tab (\t).

How do I avoid this when generating JSON?

Never build JSON by hand with string concatenation. Use your language's serializer โ€” JSON.stringify() or json.dumps() โ€” which escapes every special character correctly.


Related JSON errors

For a full reference of JSON mistakes, read Common JSON errors and how to fix them.

Press โŒ˜ K for commands