Fix: JSON Escape Characters
JSON strings use backslash escaping for special characters. Missing or malformed escape sequences cause SyntaxError at parse time. This guide covers every required escape sequence with examples and common pitfalls.
Complete Escape Sequence Reference
The JSON specification (RFC 8259, Section 7) defines exactly eight single-character escape sequences plus the Unicode escape:
| Character | Escape Sequence | Meaning | Example |
|---|---|---|---|
| " | \" | Double quote | {"say": "He said \"hi\""} |
| \ | \\ | Backslash | {"path": "C:\\Users\\name"} |
| / | \/ | Forward slash (optional) | {"url": "http:\/\/example.com"} |
| Backspace | \b | ASCII 0x08 | {"ctrl": "\b"} |
| Form feed | \f | ASCII 0x0C | {"page": "\f"} |
| Newline | \n | ASCII 0x0A (LF) | {"line": "one\ntwo"} |
| Carriage return | \r | ASCII 0x0D (CR) | {"win": "one\r\ntwo"} |
| Tab | \t | ASCII 0x09 | {"indent": "\tvalue"} |
| Unicode | \uXXXX | Any code point (4 hex) | {"euro": "\u20AC"} |
Common Causes of Escape Errors
1. Windows File Paths
Windows paths use backslashes. Each backslash must be doubled in JSON.
Invalid
{"path": "C:\Users\name"}Valid
{"path": "C:\\Users\\name"}2. Copy-Paste from Terminal Output
Terminal output may contain literal control characters (newlines, tabs). These are invisible but invalid in JSON strings.
Invalid (literal newline)
{"msg": "line one
line two"}Valid (escaped)
{"msg": "line one\nline two"}3. Regex Patterns
Regex patterns that use \\d, \\s, etc. must double every backslash in JSON.
Invalid
{"pattern": "^\d{3}-\d{4}$"}Valid
{"pattern": "^\\d{3}-\\d{4}$"}4. Unescaped Double Quotes Inside Strings
Invalid
{"quote": "He said "hello""}Valid
{"quote": "He said \"hello\""}Fix It Now — Paste Your JSON Below
The formatter below highlights escape errors at the exact character position so you can fix them quickly.
Frequently Asked Questions
What characters must be escaped in JSON?▾
JSON requires escaping 8 special sequences inside strings: \" (double quote), \\ (backslash), \/ (forward slash — optional but allowed), \b (backspace), \f (form feed), \n (newline), \r (carriage return), \t (horizontal tab). Any Unicode code point can also be written as \uXXXX using 4 hex digits.
Do I need to escape forward slashes in JSON?▾
Escaping forward slashes (\/ instead of /) is not required by the JSON specification — a bare / is valid inside a JSON string. However, some serializers escape them automatically to make the output safe for embedding inside HTML <script> tags, where the sequence </script> would otherwise end the script block.
How do I include a newline in a JSON string?▾
Use the two-character escape sequence \n (backslash followed by the letter n). A literal newline character inside a JSON string is a syntax error according to RFC 8259. For multiline content, concatenate \n escapes: "line one\nline two".
Why does my Windows file path break JSON?▾
Backslashes in Windows paths must be doubled in JSON because \ is the escape character. Write "C:\\Users\\name\\file.txt" in JSON. Alternatively, use forward slashes which Windows also accepts: "C:/Users/name/file.txt".
How do I escape Unicode characters in JSON?▾
Use the \uXXXX escape with exactly 4 hexadecimal digits, e.g. \u0041 for 'A' or \u00e9 for 'é'. Characters outside the Basic Multilingual Plane (code points above U+FFFF, such as emoji) require a surrogate pair: two consecutive \uXXXX sequences. Most languages' JSON serializers handle this automatically when you pass a native string.
More JSON error fixes
See our other error fix guides below.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.