SyntaxError: Bad escaped character in JSON at position N means there's a backslash (\) inside a string followed by something JSON doesn't recognize as a valid escape. JSON allows only a small, fixed set of escape sequences — anything else after a \ triggers this error. Here's the full list and how to fix it.
Which string-error am I getting?
- Bad escaped character — a
\is followed by something JSON doesn't allow (e.g.\x, Windows paths). - Bad control character — a raw tab/newline/null byte sits inside a string without escaping.
- Unterminated string — a string was opened with
"but never closed.
What the Error Looks Like
// V8 (Chrome / Node / Edge)
SyntaxError: Bad escaped character in JSON at position 14
// Firefox
SyntaxError: JSON.parse: bad escaped character at line 1 column 15 of the JSON data
// Safari
SyntaxError: JSON Parse error: Invalid escape character \xThe Only Escapes JSON Allows
Inside a JSON string, a backslash may be followed by exactly one of these:
\" double quote
\\ backslash
\/ forward slash
\b backspace
\f form feed
\n newline
\r carriage return
\t tab
\uXXXX a Unicode code point (exactly 4 hex digits) Anything else after a \ — \x, \', \a, \0, a Windows path like \Users, or a malformed \u12 — is a "bad escaped character."
Why It Happens
Cause 1 — Borrowing escapes from other languages
// ❌ \x and \' are valid in JS/Python, not in JSON
{ "code": "\x1b[0m", "name": "O\'Brien" }
// ✅ use a \u escape for the byte, and don't escape apostrophes
{ "code": "\u001b[0m", "name": "O'Brien" }Cause 2 — Windows file paths
// ❌ each backslash starts an invalid escape
{ "path": "C:\Users\Ada\file.json" }
// ✅ escape every backslash (or use forward slashes)
{ "path": "C:\\Users\\Ada\\file.json" }
{ "path": "C:/Users/Ada/file.json" }Cause 3 — Truncated or malformed \u escape
// ❌ \u needs exactly 4 hex digits
{ "char": "\u12" }
// ✅
{ "char": "\u0012" }Surrogate Pairs and Non-BMP Characters
JSON's \uXXXX escape is fixed at 4 hex digits, which addresses code points up to U+FFFF (the Basic Multilingual Plane). Characters above that — emoji, many CJK extensions, mathematical symbols — must be written as a UTF-16 surrogate pair:
// 😀 (U+1F600) as a surrogate pair
"\uD83D\uDE00"
// not allowed — JSON has no \U or \u{...}
"\u1F600" // bad escape (only 4 hex digits consumed; the rest is text)
"\u{1F600}" // bad escapeThis is JSON's encoding in UTF-16 form, even though the file itself is UTF-8 on disk. Two practical consequences:
- UTF-8 in the file is fine. You can write
"😀"literally; modern parsers handle it. The surrogate-pair form is only needed when you must escape. - Beware lone surrogates. A
\uD83Dwithout its matching low surrogate, or vice-versa, is technically allowed by JSON but is malformed UTF-16 — downstream consumers (especially Postgresjsonb) will reject it.JSON.stringifyproduces only well-formed pairs.
How to Fix It — Step by Step
- Jump to the reported position and find the
\that precedes an invalid character. - Is it a stray backslash? (e.g. a Windows path) — double it to
\\, or switch to forward slashes. - Is it a foreign escape like
\xor\'? — convert\xNNto\u00NN, and remove the backslash before'. - Is it a short
\u? — pad it to exactly four hex digits. - Best fix: build the JSON with
JSON.stringify(), which produces only valid escapes.
// Prevention — correct escaping is automatic
JSON.stringify({ path: 'C:\\Users\\Ada', code: '\x1b[0m' });
// → {"path":"C:\\Users\\Ada","code":"\u001b[0m"}Frequently Asked Questions
What does "Bad escaped character in JSON" mean?
A backslash inside a string is followed by a character that isn't one of JSON's allowed escapes (" \\ / b f n r t or \uXXXX). Common offenders are \x, \', and unescaped Windows paths.
How do I put a Windows path in JSON?
Double every backslash (C:\\\\Users) so each one is a valid \\ escape, or use forward slashes (C:/Users), which JSON accepts.
Is this the same as "Bad control character"?
No. "Bad escaped character" is about an invalid sequence after a backslash; "bad control character" is about a raw, unescaped control byte (tab, newline) with no backslash at all.
Fix It Now
- JSON Fix — locate and repair invalid escapes in your browser
- Bad Control Character in String Literal in JSON — raw control bytes vs escapes
- Unterminated String in JSON — when a string never closes
- How to Fix JSON.parse "Unexpected Token" Errors — the broader error guide