The Rules for Text in JSON

A JSON string is written in double quotes, and a backslash starts an escape. Only these escapes are allowed:

EscapeMeans
\"A double quote
\\A backslash
\/A forward slash (optional; / works too)
\n \r \tLine break, carriage return, tab
\b \fBackspace, form feed
\u00e9Any character by its 4-digit hex code (here é)

Two things break the rules: a backslash followed by anything else, and a real control character (such as an actual line break or tab) typed inside the quotes.

Every Message and What Caused It

JSON textJavaScript (Node.js 24, Chrome)Python 3.14
{"path": "C:\Users\Emily"}Bad escaped character in JSON at position 13Invalid \escape: line 1 column 13 (char 12)
A real line break inside "line1 / line2"Bad control character in string literal in JSON at position 15Invalid control character at: line 1 column 16 (char 15)
A real tab inside a stringBad control character in string literalInvalid control character at
"\u12" (fewer than 4 hex digits)Bad Unicode escape in JSON at position 11Invalid \uXXXX escape
"\x41"Bad escaped characterInvalid \escape
"end\" (backslash before the closing quote)Unterminated string in JSONUnterminated string starting at

Both point at the same mistake: \U in \Users is not a JSON escape. JavaScript counts from 0 and points at the U after the backslash (position 13); Python points at the backslash itself (char 12, column 13).

Windows Paths: Double Every Backslash

Wrong
{"path": "C:\Users\Emily\data.json"}
Right
{"path": "C:\\Users\\Emily\\data.json"}
Also right (Windows accepts forward slashes)
{"path": "C:/Users/Emily/data.json"}

\\ in JSON means one backslash, so the parsed value is C:\Users\Emily\data.json again. Never write the escapes by hand when a program can do it: in Python, json.dumps({"path": r"C:\Users\Emily"}) produced {"path": "C:\\Users\\Emily"}, and JavaScript's JSON.stringify gives the same.

Line Breaks and Tabs: Use \n and \t

Wrong: a real line break inside the quotes
{"note": "line1
line2"}
Right
{"note": "line1\nline2"}

This often happens when text is copied from an editor or a spreadsheet cell into a JSON file, or when a template builds JSON by gluing strings together. Build the value as normal text and let JSON.stringify or json.dumps write it, or paste the text into JSON Escape to get a correctly escaped string.

If you only need to read such a file in Python, json.loads(text, strict=False)accepts the raw line breaks: our test returned {'note': 'line1\nline2'}. JavaScript's JSON.parse has no such option.

Escaping Inside Code: The Double-Escape Trap

When JSON sits inside a string in your code, the language reads the backslashes first. In JavaScript, JSON.parse('{"a": "x\ny"}') fails with Bad control character, because \n in the JavaScript string is already a real line break before JSON.parse sees it. Write \\n in the code, or use String.raw or a separate file. Python has the same trap; use a raw string (r'...').

Quick Fixes

Frequently Asked Questions

What does Bad escaped character in JSON mean?

A backslash in a JSON string is followed by a character that is not a valid escape, most often a Windows path like C:\Users. Double every backslash (C:\\Users) or use forward slashes.

What does Bad control character in string literal mean?

A string contains a real line break or tab between its quotes. Write them as \n and \t, or create the JSON with JSON.stringify or json.dumps so they are escaped for you.

Which escapes are allowed in JSON?

Only \" \\ \/ \b \f \n \r \t and \u followed by exactly four hex digits. Anything else after a backslash makes the JSON invalid.

Can Python read JSON with raw line breaks in strings?

Yes. json.loads(text, strict=False) accepts control characters such as line breaks inside strings. JavaScript's JSON.parse has no such option.

Related Tools