</>
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.

Find this error in your own code. Paste your JSON, free and instant.Open the JSON validator

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

Related JSON Errors

View all JSON errors