Invalid Escape Characters in JSON
JSON strings support a limited set of escape sequences: \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX (Unicode). Any other backslash sequence like \a, \x, or a bare backslash before a regular character is invalid. Windows file paths are a common source of this error.
Why It Matters
The JSON parser rejects the string with an invalid escape sequence. This is especially common with Windows file paths (C:\Users\...) and regex patterns stored in JSON.
Common Causes
- Storing a Windows file path like C:\Users\john without doubling each backslash.
- Putting a regex pattern such as \d+ directly into a string instead of escaping every backslash.
- Using a non-standard escape like \x41 or \a, which JSON does not recognize.
Code Examples
{
"path": "C:\Users\john\documents",
"pattern": "\d+\.\w+",
"tab": "\t is ok but \a is not"
}{
"path": "C:\\Users\\john\\documents",
"pattern": "\\d+\\.\\w+",
"tab": "\t is ok"
}How to Fix
- 1Double every backslash in file paths: C:\\Users\\john instead of C:\Users\john.
- 2For regex patterns in JSON, escape every backslash: \\d+ instead of \d+.
- 3Use forward slashes for paths when possible: C:/Users/john/documents.
- 4Only use valid escape sequences: \", \\, \/, \b, \f, \n, \r, \t, \uXXXX.
Frequently Asked Questions
Which escape sequences are valid in a JSON string?
How do I store a Windows path in JSON?
Why does my regex pattern break the JSON?
Check Your JSON Now
Our JSON validator detects this error automatically and shows the exact line and column.
Open JSON ValidatorCloudways · Managed Cloud Hosting
Fix this JSON error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).
Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303
Related JSON Errors
Single Quotes in JSON
JSON requires straight double quotes for every string and key, so single quotes always break parsing. Learn how to fix the single quotes error fast.
Invalid Value Type in JSON
JSON only supports strings, numbers, booleans, null, objects, and arrays. Learn how to fix invalid value types like undefined, NaN, Infinity, and dates.
Unexpected Token in JSON
Fix the unexpected token error in JSON fast. See why parsers fail on trailing commas, single quotes, unquoted keys, and comments, with clear examples.