Blog
Wild & Free Tools

Bad JSON Escape Sequence — Decoding the Error and Fixing It

Last updated: January 2026 6 min read
Quick Answer

Table of Contents

  1. What the Error Actually Means
  2. Cause #1 — Windows Paths
  3. Cause #2 — Regex Patterns
  4. Cause #3 — Double-Stringified JSON
  5. Fixing the Error Quickly
  6. Frequently Asked Questions

Bad escape sequence errors come from JSON parsers when they hit a backslash followed by a character they don't recognize. JSON only allows nine escape characters: \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX. Anything else with a leading backslash triggers the error.

The fix is almost always to escape the backslash itself in the source data, before the JSON gets serialized. The rest of this guide explains where the bad backslashes usually come from and how to stop introducing them.

What the Error Means in Plain English

JSON sees a backslash and assumes "escape sequence is starting." The next character should be one of the nine valid escapes. If it's anything else — a letter, a digit, a punctuation character — the parser throws "bad escape sequence."

Sequence in JSONResult
\"Valid — literal double quote
\\Valid — literal backslash
\nValid — newline
\u00e9Valid — unicode é
\aBad escape sequence
\dBad escape sequence
\UBad escape sequence (lowercase u only)
\x41Bad escape sequence (no \x in JSON)

The error message often tells you which character followed the bad backslash, which gives you the clue about where to look.

Cause #1 — Windows File Paths

The most common bad-escape source is a Windows file path stored or transmitted as JSON. C:\Users\Alex\file.txt contains four backslashes. When this gets put inside a JSON string without escaping each backslash, the parser sees:

{"path": "C:\Users\Alex\file.txt"}

The parser sees \U, \A, \f — two bad escapes and one valid one. It errors on the first bad one.

The fix is to double every backslash before serialization:

{"path": "C:\\Users\\Alex\\file.txt"}

Most JSON serializers do this automatically when given a string value containing backslashes. The error usually means JSON was hand-built (string concatenation) instead of properly serialized. Switch to JSON.stringify, json.dumps, ConvertTo-Json, or your language's equivalent and the escaping happens for you.

Sell Custom Apparel — We Handle Printing & Free Shipping

Cause #2 — Regex Patterns Embedded in JSON

Regex patterns are full of backslashes — \d, \w, \s, \b. When you store a regex as a JSON string, every backslash needs to be doubled:

// Bad — regex stored raw:
{"pattern": "\d{3}-\d{4}"}

// Good — backslashes doubled:
{"pattern": "\\d{3}-\\d{4}"}

When the consumer reads the JSON and parses it, the doubled backslashes become single backslashes — exactly what the regex engine expects.

This is a frequent issue when copying regex from one place to another. Test patterns by sending them through a serializer rather than copy-pasting verbatim into a JSON file.

Cause #3 — Double-Stringified JSON

Code that calls JSON.stringify on a value that's already a JSON string ends up with double-escaped output:

// Original object:
const obj = { name: "Alex" };

// Once-stringified — valid JSON:
const s1 = JSON.stringify(obj);
// '{"name":"Alex"}'

// Twice-stringified — string of escaped JSON:
const s2 = JSON.stringify(s1);
// '"{\"name\":\"Alex\"}"'

If something then tries to parse s2 as if it were the original object, you get bad escape sequence errors deep in the parse.

The fix is to find where the second stringify is being called and remove it. Common culprits: logging frameworks that auto-serialize structured fields, ORM layers that serialize once on insert and again on retrieval, and copy-paste from log files where the value was already escaped.

Fixing the Error Quickly

For a one-off fix when you need the JSON to parse RIGHT NOW:

  1. Look at the error message — it usually shows the position or the bad character
  2. Find the backslash that's followed by something invalid
  3. Either double the backslash (if it should be a literal backslash) or fix the escape (if it was meant to be \n, \t, etc.)
  4. For Windows paths specifically, replace every \ with \\ in the JSON source

For a permanent fix, find where the JSON is built and use a proper serializer. Hand-built JSON via string concatenation is the root cause more often than not. Run the suspect JSON through our JSON formatter to confirm validity before passing it on.

If you're getting bad escape errors out of an API response, the API itself is broken — file a bug and either work around it (regex replace bad escapes before parsing) or wait for a fix.

Validate Your JSON

Paste JSON, get a clear error message and a fix. Free, browser-based.

Open Free JSON Escape / Unescape Tool

Frequently Asked Questions

Why does \d cause a bad escape error?

JSON only recognizes nine escape sequences. \d is valid in regex but not in JSON. Double the backslash (\\d) so JSON sees a literal backslash followed by d.

How do I escape a Windows path for JSON?

Replace every single backslash with two backslashes. C:\Users becomes C:\\Users in the JSON string.

Why is my JSON.stringify output causing escape errors elsewhere?

The downstream consumer is probably trying to parse the stringified value as if it were the original object. They should JSON.parse first, then use the result.

Does \u escape work for any character?

Yes, for the BMP (Basic Multilingual Plane). For characters above U+FFFF (most emoji), use UTF-16 surrogate pairs: \uD83D\uDE00 for the grinning face.

David Rosenberg
David Rosenberg Technical Writer

David spent ten years as a software developer before shifting to technical writing covering developer productivity tools.

More articles by David →
Launch Your Own Clothing Brand — No Inventory, No Risk