</>
ValidateHTML

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

Invalid JSON
{
  "path": "C:\Users\john\documents",
  "pattern": "\d+\.\w+",
  "tab": "\t is ok but \a is not"
}
Valid JSON
{
  "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?
Only these per RFC 8259: \" \\ \/ \b \f \n \r \t and \u followed by four hex digits. Any other backslash sequence, like \x or \a, is invalid and causes a parse error.
How do I store a Windows path in JSON?
Double every backslash: "C:\\Users\\john". Each \\ encodes one literal backslash. Alternatively use forward slashes, since "C:/Users/john" works on Windows in most contexts and needs no escaping.
Why does my regex pattern break the JSON?
A regex backslash is taken as the start of a JSON escape. \d is not a valid escape, so it errors. Write \\d inside the JSON string so the parser produces a literal backslash followed by d for your regex engine.

Check Your JSON Now

Our JSON validator detects this error automatically and shows the exact line and column.

Open JSON Validator
Recommended

Cloudways · 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

Start free trial

Related JSON Errors

View all JSON errors