Invalid Escape in JSON – Find Bad Backslashes

Local only

A backslash inside a JSON string must begin a supported escape such as \n, \t, \uXXXX, \", or \\. Raw Windows paths and unsupported sequences can make otherwise readable strings invalid JSON.

Indent

39 chars · 3 lines

Two-way sync · Edit either side and the other updates automatically.

Invalid JSONInvalid escape sequence in string
Line 2Column 15Character 17Found “U”
"path": "C:\Users\Ada\new-folder"

JSON string escape error

How to diagnose invalid JSON escape sequences

JSON gives backslash a special meaning inside strings. Only defined escapes are allowed, so copied Windows paths, regular expressions, or manually escaped text can fail when a backslash is followed by an unsupported character or an incomplete Unicode sequence. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Browser-local JSON processing
  • Route-specific malformed JSON example
  • Focused parser or repair guidance
  • Broken and corrected JSON example
  • Related JSON problem navigation

Steps

  1. Paste the raw JSON text and inspect the backslash nearest the parser failure.
  2. Replace unsupported raw backslashes with valid JSON escapes, commonly \\ for a literal backslash.
  3. Validate the raw JSON again before embedding it in JavaScript, shell, or another string layer.

Common escape mistakes in JSON strings

JSON supports a defined set of escapes for quotation marks, backslashes, control characters, and four-hex-digit Unicode escapes. A sequence such as \U or an incomplete \u code is not part of the JSON grammar.

  • Windows paths with single raw backslashes.
  • Regular expressions copied into JSON without escaping backslashes.
  • Incomplete or non-hex Unicode escape sequences.

Raw JSON and JavaScript source need different escaping counts

If JSON text is itself stored inside a JavaScript string, JavaScript consumes one escape layer before JSON.parse sees the text. Debug the raw value passed to JSON.parse rather than counting backslashes only in source code.

Windows path escape example

A literal backslash in raw JSON must be represented as two backslash characters.

Invalid raw JSON

{
  "path": "C:\Users\Ada"
}

Valid raw JSON

{
  "path": "C:\\Users\\Ada"
}

Common questions

Frequently asked questions

Why are Windows paths often invalid JSON?

A single backslash starts a JSON escape sequence. Literal path separators therefore need to be escaped as two backslash characters in raw JSON text.

What escapes are valid in JSON strings?

JSON supports escaped quote, backslash, slash, backspace, form feed, newline, carriage return, tab, and Unicode escapes written as \u followed by four hexadecimal digits.

Why do I sometimes need four backslashes in JavaScript source?

When JSON text is embedded inside a JavaScript string, one escape layer belongs to JavaScript and another belongs to JSON. Inspect the runtime string passed to JSON.parse to see the actual JSON text.

Debugging a specific JSON issue? Browse JSON troubleshooting.