JSON Invalid Escape Sequence
Inside a JSON string, only certain characters can follow a backslash. Any other character after \ causes an invalid escape error.
Common causes
- Using \x or \u incorrectly.
- Escaping a character that does not need escaping.
- Single backslash at end of string.
- Invalid \uXXXX (wrong hex digits or length).
How to fix
- Use only \ " \ / b f n r t and \uXXXX (four hex digits).
- To include a backslash, use \\.
- For Unicode, use \u followed by exactly four hex digits.
Examples
Bad
"path: C:\users\file"
Good
"path: C:\\users\\file"
FAQ
- What are valid JSON escape sequences?
- \" \\ \/ \b \f \n \r \t and \uXXXX for Unicode.
- How do I put a newline in a JSON string?
- Use \n inside the string, not a real newline.
Fix it now
Try in validator (prefill this example)