JSON Escape Special Characters β The Complete Reference
- JSON has nine valid escape sequences β anything else is invalid and will error.
- Required escapes: double quote, backslash, and control characters U+0000 to U+001F.
- Optional but allowed: forward slash and any character via \uXXXX.
Table of Contents
JSON's escape rules are short β there are exactly nine recognized escape sequences. Anything else is invalid and will trigger a parse error. This is the complete reference: every escape, when it's required, and when it's optional.
The Complete List of Valid JSON Escapes
| Escape | Meaning | When required |
|---|---|---|
\" | Double quote | Always inside strings |
\\ | Backslash | Always inside strings |
\/ | Forward slash | Optional β JSON allows raw / too |
\b | Backspace (U+0008) | Always (raw control char invalid) |
\f | Form feed (U+000C) | Always |
\n | Newline (U+000A) | Always |
\r | Carriage return (U+000D) | Always |
\t | Tab (U+0009) | Always |
\uXXXX | Any unicode character | Required for U+0000 through U+001F (other than the named ones above) |
Notice what's NOT on the list: \' (single quote escape β JSON doesn't have one because single quotes are not delimiters), \a (bell β common in C, not in JSON), \v (vertical tab β also from C), \x41 (hex escape β JSON uses \uXXXX instead), \0 (null β use \u0000).
Any backslash followed by anything outside the valid list is a parse error.
Required vs Optional Escapes
Required means JSON syntax is invalid without the escape.
Optional means the escape is allowed but the raw character is also allowed.
The required escapes inside a string are:
- Double quote β would otherwise terminate the string
- Backslash β would otherwise be interpreted as the start of an escape
- Any character below U+0020 β the spec forbids raw control characters in strings
Optional escapes:
- Forward slash β both
/and\/are valid. Some implementations escape it for HTML safety; most don't. - Any character above U+007F β both raw UTF-8 and
\uXXXXare valid. Most modern JSON keeps them raw.
Most serializers escape only what's required and leave optional characters raw. The output is shorter and equally valid.
Sell Custom Apparel β We Handle Printing & Free ShippingThe Unicode Escape Pattern
Any character can be expressed as \u followed by four hex digits. The hex digits give the Unicode code point.
| Character | Code point | Escape |
|---|---|---|
| A | U+0041 | \u0041 |
| Γ© | U+00E9 | \u00e9 |
| β | U+2660 | \u2660 |
| δΈ | U+4E2D | \u4e2d |
For characters above U+FFFF (most emoji, some CJK extensions), JSON uses UTF-16 surrogate pairs β two \u escapes:
| Character | Code point | Escape |
|---|---|---|
| π | U+1F600 | \uD83D\uDE00 |
| π | U+1F44D | \uD83D\uDC4D |
This surrogate-pair behavior is inherited from JavaScript's UTF-16 string representation. Most consumers handle it transparently β you rarely need to construct surrogate pairs by hand.
Common Misconceptions About JSON Escapes
Myth: JSON requires escaping forward slashes.
It doesn't. The spec allows \/ as an optional escape. Most serializers leave forward slashes raw. The exception is some HTML-embedding contexts where escaping / as \/ prevents the string </script> from breaking out of a script tag.
Myth: JSON requires escaping non-ASCII characters.
It doesn't. JSON is UTF-8 by spec. Raw Γ©, δΈ, π are all valid inside strings. Some legacy serializers escape them as \u for safety; modern ones leave them raw.
Myth: JSON supports the same escapes as JavaScript strings.
Mostly but not entirely. JavaScript supports \v, \0, \x41, single-quote escape, and others that JSON doesn't. Pasting a JS string literal into a JSON document can produce invalid JSON if any of these slipped in.
Myth: \u escapes need uppercase hex.
Either case works. \u00E9 and \u00e9 are both valid. Some serializers prefer one or the other; the parser doesn't care.
How Different Serializers Handle These Rules
Most serializers escape the same things β quote, backslash, control characters β but differ on the optional cases. Quick reference:
| Serializer | Escapes / | Escapes non-ASCII |
|---|---|---|
| JavaScript JSON.stringify | No | No |
| Python json.dumps (default) | No | Yes (use ensure_ascii=False to disable) |
| PHP json_encode (default) | Yes (use JSON_UNESCAPED_SLASHES to disable) | Yes (use JSON_UNESCAPED_UNICODE to disable) |
| Go json.Marshal | No | No (HTML-safe escapes <, >, &) |
| .NET System.Text.Json | No (in non-HTML mode) | No (in non-HTML mode) |
| Java Jackson | No | No |
The result is equivalent JSON in all cases β just different verbosity. If you're comparing JSON output across implementations and the bytes don't match, optional escape choices are usually the reason.
Check Your JSON Escapes
Paste your JSON to escape or unescape per the rules in this reference.
Open Free JSON Escape / Unescape ToolFrequently Asked Questions
Does JSON support the \' escape for single quotes?
No. Single quotes are not string delimiters in JSON, so they need no escape. \' is invalid.
Why does my JSON have \u escapes for normal characters like Γ©?
Some serializers default to escaping non-ASCII (Python json.dumps, PHP json_encode). Both forms are valid; the raw form is usually preferred for readability.
How do I escape an emoji in JSON?
Either leave it raw (preferred) or use the surrogate pair: π becomes \uD83D\uDE00.
Can I escape any character with \u, even if there's a shorter escape?
Yes. \u0009 and \t both produce a tab. The shorter form is preferred for readability but both are valid.

