"Bad escaped character" in JSON: backslashes in Windows paths
Why C:\Users breaks JSON, the exact error messages in Chrome, Node.js and Python, and how to escape backslashes.
Error messages you may see
| Chrome · Edge · Node.js | SyntaxError: Bad escaped character in JSON at position 13 (line 1 column 14) |
|---|---|
| Older Chrome · Node.js 18 and earlier | SyntaxError: Unexpected token U in JSON at position 13 |
| Python json.loads | json.decoder.JSONDecodeError: Invalid \escape: line 1 column 13 (char 12) |
| This tool | Line 1, Col 13: Invalid escape '\U' |
Why it happens
A backslash starts an escape sequence in JSON, and only \" \\ \/ \b \f \n \r \t and \uXXXX are allowed. A Windows path such as C:\Users contains \U, which is not a valid escape.
Invalid
{"path": "C:\Users\kim"}
How to fix
Write each backslash twice (C:\\Users\\kim) or use forward slashes (C:/Users/kim), which Windows also accepts. Serializing with JSON.stringify() or json.dumps() escapes them automatically.
Fixed
{"path": "C:\\Users\\kim"}