Invalid escape sequence in a JSON string
A backslash followed by a character JSON does not define. The complete set is `\" \\ \/ \b \f \n \r \t` and `\uXXXX`. Windows paths are the usual culprit: `C:\Users` contains `\U`, which is not an escape.
The input
{"a": "c:\x41"}{"a": "c:\\x41"}How to fix it
Escape the backslash itself: write `C:\\Users`. Or use forward slashes, which Windows accepts in most APIs.
`\x41` is valid in JavaScript, Python and C but not in JSON. JSON has no hex escape — only `\u`.
What each parser reports
Every message below was captured by running this exact input through the parser named. 19 of 21 parsers rejected it; 2 accepted it.
| Parser | Exact message |
|---|---|
| CPython json.loads CPython 3.12.3 | Invalid \escape: line 1 column 10 (char 9)what this message means → |
| encoding/json Unmarshal Go go1.22.2 | invalid character 'x' in string escape codewhat this message means → |
| Gson Java 21.0.12 | Invalid escape sequence at line 1 column 12 path $.awhat this message means → |
| Gson JsonParser (lenient off) Java 21.0.12 | Invalid escape sequence at line 1 column 12 path $.awhat this message means → |
| hjson Node.js 22.22.2 | Bad string at line 1,10 >>>"a": "c:\x41"} ...what this message means → |
| Jackson ObjectMapper Java 21.0.12 | Unrecognized character escape 'x' (code 120)what this message means → |
| JavaScriptCore JSON.parse JavaScriptCore (Bun 1.4.1) | JSON Parse error: Invalid escape character xwhat this message means → |
| json-bigint Node.js 22.22.2 | Bad string |
| JSON5 Node.js 22.22.2 | accepted — no error |
| JSON::PP Perl 5.038002 | illegal backslash escape sequence in string, at character offset 9 (before "\\x41"}")what this message means → |
| json_decode PHP 8.3.6 | Syntax error |
| Newtonsoft.Json JsonConvert Newtonsoft.Json 13.0.3 on .NET 8.0.30 | Bad JSON escape sequence: \x. Path 'a', line 1, position 11.what this message means → |
| Newtonsoft.Json JsonTextReader Newtonsoft.Json 13.0.3 on .NET 8.0.30 | Bad JSON escape sequence: \x. Path 'a', line 1, position 11.what this message means → |
| orjson CPython 3.12.3 | invalid escaped sequence in string: line 1 column 10 (char 9)what this message means → |
| Ruby JSON.parse Ruby 3.2.3 | accepted — no error |
| serde_json::from_str Rust (serde_json 1.x) | invalid escape at line 1 column 11what this message means → |
| SpiderMonkey JSON.parse SpiderMonkey 115 | JSON.parse: bad escaped character at line 1 column 11 of the JSON datawhat this message means → |
| System.Text.Json Deserialize .NET 8.0.30 | 'x' is an invalid escapable character within a JSON string. The string should be correctly escaped. Path: $ | LineNumber: 0 | BytePositionInLine: 10.what this message means → |
| System.Text.Json JsonDocument .NET 8.0.30 | 'x' is an invalid escapable character within a JSON string. The string should be correctly escaped. LineNumber: 0 | BytePositionInLine: 10.what this message means → |
| ujson CPython 3.12.3 | Unrecognized escape sequence when decoding 'string'what this message means → |
| V8 JSON.parse Node.js 22.22.2 | Bad escaped character in JSON at position 10 (line 1 column 11)what this message means → |
What the specification says
The exact sections that govern this error. Descriptions are our paraphrase; follow the links for the normative text.
| Body | Section |
|---|---|
| IETF | A string begins and ends with a quotation mark. Any Unicode character may appear between them except the quotation mark, the reverse solidus, and the control characters U+0000 through U+001F, which the section requires to be escaped. It also fixes the escape set and the \uXXXX form. |
| Ecma International | A string is code points wrapped in quotation marks; the quotation mark, reverse solidus and U+0000–U+001F must be escaped. Table 3 fixes the escape sequences. |
Other errors in this category
Literal newline inside a JSON string
A real line break between the quotes. JSON forbids unescaped control characters (U+0000 to U+001F) inside strings, and a newline i…
Literal tab inside a JSON string
A raw tab character inside string content. Like a newline, it is a control character and must be escaped.…
Malformed \u escape in a JSON string
A `\u` not followed by exactly four hexadecimal digits.…
Truncated \u escape in a JSON string
A `\u` escape with fewer than four hex digits, typically where a string was cut mid-escape by a length limit.…
Lone surrogate in a JSON string
A high surrogate (`\uD800`–`\uDBFF`) with no following low surrogate. Characters outside the Basic Multilingual Plane — emoji, mos…
Raw NUL byte inside a JSON string
A U+0000 byte in string content, usually from a C string boundary, a fixed-width database column, or binary data that was treated …