JSON Escape / Unescape
JSON escaping converts raw text into a string that is safe to place inside a JSON document, replacing characters like the double quote, backslash, and control characters with escape sequences. Use the Escape direction to prepare text for JSON, or Unescape to decode a JSON string literal back into plain text. Everything runs in your browser -- nothing is sent to a server.
JSON Escape Sequences
The JSON specification (RFC 8259) defines exactly which characters must be escaped inside a string and how. Two characters are mandatory to escape -- the double quote and the backslash -- along with every control character below U+0020.
| Character | Escape | Meaning |
|---|---|---|
| Double quote | \" | Ends a string if not escaped |
| Backslash | \\ | Starts an escape sequence |
| Backspace | \b | U+0008 control character |
| Form feed | \f | U+000C control character |
| Newline | \n | U+000A line feed |
| Carriage return | \r | U+000D |
| Tab | \t | U+0009 horizontal tab |
| Other control char | \u00XX | Any U+0000-U+001F without a short form |
| Forward slash | \/ (optional) | Legal unescaped; escape is allowed but not required |
Escape vs. Unescape
These are inverse operations. Escape takes raw text -- with literal newlines, quotes, and Unicode -- and produces a JSON string body where those characters are represented by escape sequences. For example the two-line text Hello "World" followed by a newline and done becomes Hello \"World\"\ndone. With "Wrap in double quotes" enabled you get the complete literal "Hello \"World\"\ndone" ready to drop into a JSON document.
Unescape reverses this. It reads a JSON string literal -- with or without the surrounding double quotes -- and decodes the escape sequences back into real characters. \n becomes a newline, \t becomes a tab, and \uXXXX becomes the matching Unicode character. Surrogate pairs such as \ud83d\ude00 are combined into a single emoji rather than two broken halves.
A common workflow is to copy a stringified value out of a log line or an API response, unescape it to read the underlying text, edit it, and then escape it again to paste it back. The Swap button moves the current output into the input and flips the direction, which makes round-tripping fast.
Worked Examples
| Raw text | Escaped (JSON body) |
|---|---|
She said "hi" | She said \"hi\" |
C:\Users\dev | C:\\Users\\dev |
| Line one (newline) line two | Line one\nline two |
| Tab separated | Tab\tseparated |
café (with non-ASCII on) | caf\u00e9 |
| Smiley emoji | \ud83d\ude00 (non-ASCII on) |
When the "Escape all non-ASCII" option is off, characters such as é and emoji are left as-is -- they are valid inside a UTF-8 encoded JSON string. Turn the option on for ASCII-only output that survives any transport or encoding.
Common Pitfalls
- Double-escaping. Running escape twice turns
\ninto\\n. If your text already contains escape sequences and you want to keep them literal, that is correct -- but if you meant to escape raw text, escape it only once. - Incomplete
\uescapes. A\umust be followed by exactly four hexadecimal digits.\u12or\uZZZZis invalid and the unescape direction will report it instead of guessing. - Lone surrogates. A high surrogate (
\uD800-\uDBFF) must be followed by a low surrogate (\uDC00-\uDFFF). A surrogate on its own is not a valid character and is flagged as an error. - Forgetting the quotes context. The escaped body is meant to go inside double quotes. If you paste it without quotes into a JSON value slot, the JSON is incomplete. Use the wrap option to get a complete literal.
- Confusing JSON escaping with HTML or URL escaping. JSON does not use
<or%20. Pick the tool that matches the destination format.
Frequently Asked Questions
What does escaping a JSON string do?
Escaping converts characters that are not allowed raw inside a JSON string into safe escape sequences. The double quote becomes \", the backslash becomes \\, and control characters like newline and tab become \n and \t. The result can be placed between double quotes in a JSON document without breaking the syntax.
Which characters must be escaped in JSON?
RFC 8259 requires escaping the double quote ("), the backslash (\), and all control characters from U+0000 to U+001F. Five of those control characters have short escapes -- \b, \f, \n, \r, and \t -- and any other control character is escaped as \u00XX. All other characters, including most Unicode, may appear unescaped in a UTF-8 JSON string.
What is the difference between escape and unescape?
Escape takes raw text and produces a JSON-safe string literal by adding escape sequences. Unescape does the reverse: it reads a JSON string literal and decodes the escape sequences back into the original characters. Escaping prepares text for JSON; unescaping recovers text from JSON.
Does this tool handle Unicode and surrogate pairs?
Yes. When unescaping, \uXXXX sequences are decoded to their characters, and a high surrogate (\uD800-\uDBFF) followed by a low surrogate (\uDC00-\uDFFF) is combined into the correct supplementary-plane character, such as an emoji. When escaping, you can optionally escape every non-ASCII character as \uXXXX for maximum portability.
Should I wrap the escaped string in double quotes?
It depends on the destination. Enable "Wrap in double quotes" when you want a complete JSON string literal to drop directly into a JSON document. Leave it off when you only need the escaped body to place inside quotes you already have -- for example a string already opened in your source code.
Why do I get an error when unescaping?
Unescaping fails when the input contains an invalid escape sequence: a backslash followed by an unsupported character, an incomplete \u escape with fewer than four hex digits, or a lone surrogate. The tool reports the exact problem and character position instead of producing wrong output, so you can fix the source string.
Do I need the surrounding quotes when unescaping?
No. The unescape direction accepts a JSON string literal with or without surrounding double quotes. If the input begins and ends with a double quote, the tool treats it as a quoted literal and strips them; otherwise it decodes the content directly. This lets you paste a value copied from anywhere.
Does escaping change the forward slash?
By default no. The forward slash (/) is legal inside a JSON string and needs no escaping, so it is left unchanged. JSON does allow the optional \/ escape, sometimes used to avoid the sequence </ inside HTML <script> tags, but it is not required and is not applied here.
How is JSON escaping different from URL or HTML escaping?
Each format escapes different characters for a different context. JSON escaping protects the double quote, backslash, and control characters inside a JSON string. URL encoding uses percent-escapes like %20. HTML escaping replaces characters such as < and & with entities like < and &. They are not interchangeable -- use the tool that matches where the text will go.
Is my text sent to a server?
No. All escaping and unescaping runs entirely in your browser using JavaScript. Your text is never uploaded or logged. You can disconnect from the internet and the tool works identically offline.
Privacy & Limitations
- Client-side only. No data is sent to any server. No cookies, no tracking of typed or pasted content.
- String escaping, not full JSON. This tool escapes and unescapes the contents of a single JSON string. To format or validate a whole JSON document, use the JSON Formatter or JSON Validator.
- Strict unescaping. Invalid escape sequences and lone surrogates are reported as errors rather than silently repaired, so the output always reflects valid input.
Related Tools
- JSON Formatter -- beautify, minify, and validate full JSON documents
- JSON Validator -- check JSON syntax with detailed error reporting
- URL Encoder / Decoder -- percent-encode and decode text for URLs
- Base64 Encode/Decode -- encode and decode Base64 strings
- HTML Entity Encoder/Decoder -- encode and decode HTML entities
Related Tools
View all toolsBig-O Notation Visualizer
Interactive plot of O(1) through O(n!) complexity curves with operation count comparison
JSON Formatter
Format and beautify JSON with proper indentation
JSON Validator
Validate JSON syntax and show errors
CSV to JSON Converter
Convert CSV data to JSON format with auto-detection
JSON to CSV Converter
Convert JSON arrays to CSV format with nested object handling
JWT Decoder
Decode JWT tokens and display header and payload
JSON Escape/Unescape FAQ
What does escaping a JSON string do?
Escaping converts characters that are not allowed inside a raw JSON string into safe escape sequences. Double quotes become \", backslashes become \\, and control characters like newline and tab become \n and \t. The result can be safely pasted between double quotes in JSON without breaking the syntax.
Which characters must be escaped in JSON?
The JSON specification (RFC 8259) requires escaping the double quote ("), the backslash (\), and all control characters U+0000 through U+001F. Common control characters have short escapes: \b (backspace), \f (form feed), \n (newline), \r (carriage return), and \t (tab). Any other control character is escaped as \u00XX.
What is the difference between escape and unescape?
Escape takes raw text and produces a JSON-safe string literal -- it adds backslashes and escape sequences. Unescape does the reverse: it takes a JSON string literal and decodes the escape sequences back into the original raw characters. Escaping prepares text for JSON; unescaping recovers text from JSON.
Does this tool handle Unicode and surrogate pairs?
Yes. When unescaping, \uXXXX sequences are decoded to their characters, and surrogate pairs (a high surrogate \uD800-\uDBFF followed by a low surrogate \uDC00-\uDFFF) are combined into the correct emoji or supplementary-plane character. When escaping, you can optionally escape all non-ASCII characters as \uXXXX for maximum portability.
Should I wrap the escaped string in double quotes?
It depends on where you paste the result. Enable 'Wrap in double quotes' when you want a complete JSON string literal you can drop directly into a JSON document. Leave it off when you only need the escaped content to place inside quotes you already have, such as a string already started in your code.
Why do I get an error when unescaping?
Unescaping fails when the input contains an invalid escape sequence -- for example a backslash followed by an unsupported character, an incomplete \u escape with fewer than four hex digits, or a lone surrogate. The tool reports the exact problem and position instead of producing wrong output, so you can fix the source string.
Do I need to include the surrounding quotes when unescaping?
No. The unescape direction accepts a JSON string literal with or without surrounding double quotes. If the input begins and ends with a double quote, the tool treats it as a quoted literal and strips them; otherwise it decodes the content directly. This makes it easy to paste a value copied from anywhere.
Does escaping change the forward slash?
By default no. The forward slash (/) is a legal character inside a JSON string and does not require escaping, so this tool leaves it unchanged. JSON does allow the optional \/ escape, which is sometimes used to avoid the sequence </ inside HTML script tags, but it is not required and is off by default here.
Is my text sent to a server?
No. All escaping and unescaping runs entirely in your browser using JavaScript. Your text is never uploaded or logged. You can disconnect from the internet and the tool works identically offline.
How is JSON escaping different from URL or HTML escaping?
Each format escapes different characters for different contexts. JSON escaping protects double quotes, backslashes, and control characters inside a JSON string. URL encoding uses percent-escapes like %20 for characters not allowed in a URL. HTML escaping replaces characters like < and & with entities such as < and &. They are not interchangeable.