Bad escaped character in JSON at position N (line L column C)
JSON allows exactly nine escape sequences: \" \\ \/ \b \f \n \r \t and \uXXXX. Anything else after a backslash is an error. A single backslash in a Windows path is almost always the cause, because \U, \P and \D are not escapes.
Paste your JSON and see exactly where it breaks
Nothing you paste leaves your browser. The connect-src allowlist makes that a browser guarantee rather than a promise. Check it yourself
What actually causes it
Ranked by how often each one turns out to be the answer.
-
01 A Windows file path with single backslashes
This is the dominant cause. Every backslash in a JSON string must be doubled. Forward slashes also work on Windows in most contexts and avoid the problem entirely.
Breaks
{ "path": "C:\Users\priya\config.json" }Works
{ "path": "C:\\Users\\priya\\config.json" } -
02 A hex escape borrowed from another language
JSON has no \x escape. C, Python and JavaScript all accept \x41 for the letter A; JSON requires \u0041.
Breaks
{ "c": "\x41" }Works
{ "c": "\u0041" } -
03 A regular expression pasted into a string
Patterns like \d, \s and \w are not JSON escapes. Every backslash in the pattern needs doubling before it goes into a JSON string.
Breaks
{ "pattern": "^\d{3}-\d{4}$" }Works
{ "pattern": "^\\d{3}-\\d{4}$" } -
04 A single-quote escape
\' is valid in JavaScript and JSON5 but not in JSON. Inside a double-quoted string an apostrophe needs no escape at all.
The same mistake in other runtimes
The underlying problem is identical; only the wording differs. If a colleague reports one of these, they are looking at the same thing you are.
| Python | Invalid \escape: line 1 column 9 (char 8) |
|---|
Questions
- Why does my Python string look right but still fail?
- Because the backslash is consumed twice: once by the Python string literal and once by JSON. Use a raw string for the literal, or build the object and call json.dumps rather than writing JSON by hand.
- Is \/ really allowed?
- Yes. Escaping a forward slash is optional in JSON and both forms mean the same character. It exists so that JSON can be safely embedded inside a script tag in HTML, where the sequence </ would end the element.
Fix it now
Paste the payload into the tool above, or go straight to the one built for this job.
Escape a string correctly