JSON Error: Bad Control Character in String
SyntaxError: Bad control character in string literal in JSON at position XWhat Causes This Error?
This error occurs when a JSON string contains a raw control character — a character that must be escaped in JSON strings but wasn't. The most common offenders are actual newline characters (ASCII 10), carriage returns (ASCII 13), and tab characters (ASCII 9) embedded directly in a string. JSON requires these to be written as escape sequences: \n, \r, and \t respectively. Backslashes inside strings must also be doubled: \\.
Common Causes
- arrow_rightA real newline character inside a string value (from pressing Enter in a text field)
- arrow_rightA Windows path using single backslashes: C:\Users\Alice
- arrow_rightA regex pattern with backslashes copied directly into JSON
- arrow_rightLogging output that included raw control characters pasted into JSON
- arrow_rightAn API response that returned a multi-line string without proper JSON encoding
Example: Broken vs Fixed JSON
cancel Invalid JSON (causes the error)
{
"message": "Hello
World",
"path": "C:\Users\Alice\Documents"
}check_circle Fixed JSON (valid)
{
"message": "Hello\nWorld",
"path": "C:\\Users\\Alice\\Documents"
}Step-by-Step Fix Guide
Escape newlines
Replace all real newline characters inside string values with the two-character sequence \n. In most editors, you can search for a literal newline in regex mode (\n in the search field) and replace with \\n.
Escape backslashes
Every backslash in a JSON string must be written as \\. A Windows path like C:\Users must become C:\\Users.
Escape tabs
Replace literal tab characters inside strings with \t.
Use JSON.stringify() to safely serialize
If you're generating JSON in JavaScript, always use JSON.stringify() rather than building the string manually. It handles all required escape sequences automatically.
Validate
Paste the corrected JSON into the JSON Validator. Control character errors are often the only thing blocking a parse once other issues are fixed.
Fix This Error Instantly
Paste your JSON into the validator to get the exact line number and error description. Then use the JSON Editor to make the fix and re-validate in one workflow.
Related JSON Errors
Part of the JSON Toolkit
Explore All JSON Tools
Free online tools for every JSON task — format, validate, convert, compare, and more.