๐ฃ JSON Escape and Unescape
By Shihab Mia ยท Updated 2026-08-03
Type above to see the escaped output.
This tool escapes and unescapes JSON strings, both ways, in your browser. Paste raw text and it produces a safe JSON string value with quotes, backslashes, newlines and tabs escaped, ready to drop into a JSON document or a code literal. Switch to unescape mode to turn an escaped JSON string back into the plain, human-readable text it represents. Nothing is uploaded: everything runs locally with the browser built-in JSON parser.
What is the JSON Escape Unescape?
JSON has a small but strict set of rules for what may appear inside a string. The string is wrapped in double quotes, and certain characters are not allowed to sit raw between those quotes: the double quote itself, the backslash, and the ASCII control characters (anything below code point 0x20, such as newline, carriage return and tab). To include them you escape them with a backslash, so a double quote becomes \", a backslash becomes \\, a newline becomes \n, a tab becomes \t, and an arbitrary control character becomes a \u escape like \u0000. Escaping is simply the act of rewriting raw text so it obeys these rules, and the rules themselves come from RFC 8259, the specification every JSON parser is built against.
The most reliable way to escape text is the language built-in JSON serializer rather than a hand-written replace. This tool uses the browser JSON.stringify function, which turns your text into a fully quoted, fully escaped JSON string, then trims the outer quotes so you get just the escaped body (you can keep the quotes with one checkbox). Unescaping is the exact inverse: it uses JSON.parse to decode every escape sequence back to the character it stands for. Using the same engine that browsers, Node and most servers use means the result matches what real JSON parsers will accept, with no edge cases missed.
Every mainstream language ships an equivalent pair of functions, because they all implement the same JSON standard. Python has json.dumps and json.loads, Java projects typically use a library such as Jackson or Gson, C# has System.Text.Json, and PHP has json_encode and json_decode. The escaped output is identical across all of them for the required characters, quotes, backslashes and control characters always come out the same way, so a string escaped in this browser tool will parse correctly in a Python, Java or C# backend without modification.
Escaping matters beyond simple string storage. A frequent real-world case is embedding a JSON payload inside another JSON field, for example a webhook body that carries a raw JSON string as one of its values, where the inner braces and quotes must all be escaped or the outer document stops parsing at the first stray character. Another is putting JSON output into an HTML page inside a script tag, where a literal closing tag sequence inside the string can break the page, so some tools optionally escape the forward slash to guard against it. Multi-line text, log lines and file paths on Windows (full of backslashes) are also common sources of characters that need escaping before they are safe to embed.
Unicode characters outside the Basic Multilingual Plane, such as most emoji, are represented in JSON as a surrogate pair, two \u escapes in sequence rather than one. JSON.stringify handles this automatically, splitting a single emoji character into its two UTF-16 code units and escaping each with \uXXXX, and JSON.parse reassembles the pair back into the original character on the way back. You do not need to do anything special, the browser engine takes care of it, but it explains why a short string of emoji can turn into a much longer block of escape sequences.
Escaping and unescaping are reversible: escape a piece of text, then unescape the result, and you are back to the original. Get the escaping wrong, or apply it twice by mistake, and a parser downstream will either reject the string outright or silently produce the wrong text, which is a common and hard-to-spot source of bugs in API integrations. A correct, automatic escape done once, at the right point in the pipeline, avoids both failure modes.
When to use it
- Turning a block of text, with quotes and line breaks, into a single safe JSON string value you can paste into a request body or config file.
- Embedding a JSON snippet inside another JSON field, where the inner braces and quotes must all be escaped.
- Building a string literal for source code by escaping text the same way the language would.
- Reading an escaped string out of a log file or API response by unescaping it back into plain, multi-line text.
- Preparing a JSON string value to pass safely as a command line argument, environment variable, or curl payload.
- Debugging a failing API request by unescaping the payload to see the exact raw text, quotes and line breaks a parser is choking on.
How to use the JSON Escape Unescape
- Pick Escape to convert raw text into a JSON string, or Unescape to convert a JSON string back to raw text.
- Type or paste your text into the input box, including multi-line text if needed.
- Read the converted result in the output box below, it updates as you type.
- Optionally tick "Wrap output in double quotes" to include the surrounding quotes around the escaped value.
- Press Copy to put the result on your clipboard, or Swap to send the output back into the input.
Formula & method
Worked examples
Escape the raw text: She said "hi" then pressed Tab (a real tab) and a newline.
- Start with the raw characters: She said "hi" [tab] [newline]
- JSON.stringify wraps it in quotes and escapes each special character.
- The double quotes around hi become \" and \"
- The tab becomes \t and the newline becomes \n
- Trim the outer quotes to get just the escaped body.
Result: She said \"hi\" then pressed Tab\t and a newline.\n
Unescape the JSON string value: C:\\Users\\me\\file.txt
- Input is the escaped text C:\\Users\\me\\file.txt
- Wrap it in quotes so JSON.parse sees a complete string token.
- JSON.parse reads each \\ as a single backslash.
- No other escape sequences are present.
Result: C:\Users\me\file.txt
Escape a JSON snippet so it can sit inside another JSON field, for example {"payload": "..."}.
- Start with the inner JSON text: {"status":"ok","code":200}
- JSON.stringify escapes every double quote in that text as \"
- The colons, digits and braces are not special and stay as they are.
- The escaped body is safe to place as the value of an outer JSON string field.
Result: {\"status\":\"ok\",\"code\":200}
Characters that must be escaped inside a JSON string
| Character | Escaped form | Meaning |
|---|---|---|
| " | \" | Double quote |
| \ | \\ | Backslash |
| newline | \n | Line feed (U+000A) |
| carriage return | \r | Carriage return (U+000D) |
| tab | \t | Horizontal tab (U+0009) |
| other control char | \uXXXX | Any character below U+0020 |
Optional escapes JSON allows but does not require
| Character | Escaped form | Note |
|---|---|---|
| / | \/ | A forward slash may be escaped but never has to be. |
| backspace | \b | Control character U+0008. |
| form feed | \f | Control character U+000C. |
How to escape and unescape a JSON string in popular languages
| Language | Escape | Unescape |
|---|---|---|
| JavaScript / Node.js | JSON.stringify(text) | JSON.parse(text) |
| Python | json.dumps(text) | json.loads(text) |
| Java (Jackson) | objectMapper.writeValueAsString(text) | objectMapper.readValue(text, String.class) |
| C# (.NET) | JsonSerializer.Serialize(text) | JsonSerializer.Deserialize<string>(text) |
| PHP | json_encode(text) | json_decode(text) |
Common mistakes to avoid
- Escaping by hand and missing a case. Replacing only quotes and forgetting backslashes, newlines or control characters produces a string that breaks at parse time. Using the JSON serializer, as this tool does, covers every required case automatically.
- Double-escaping already-escaped text. Running escape twice turns \n into \\n, so the parser later returns a literal backslash-n instead of a newline. Escape exactly once, and use Unescape to reverse it.
- Confusing the escaped body with the full string. The escaped body has no surrounding quotes, while a complete JSON string value does. Use the "Wrap output in double quotes" option when you need the full quoted value, and leave it off when you are inserting into an existing pair of quotes.
- Pasting quotes into unescape mode incorrectly. Unescape accepts text with or without the outer quotes, but a stray unescaped quote in the middle is invalid JSON and will be rejected. Make sure inner quotes are written as \" before unescaping.
- Assuming JSON escaping is the same as JavaScript string escaping. JavaScript string literals allow extra escapes that JSON does not, such as \0, \xFF, or single-quoted strings. JSON only recognizes the small fixed set of escapes in the reference table above, anything else is invalid JSON even if a browser console would accept it.
- Not realizing the forward slash escape is optional. Some tools and older code escape every forward slash as \/, which is valid but not required. Seeing \/ in someone else output is not a sign of a different escaping scheme, both forms decode to the same character.
Glossary
- Escape
- Rewriting a character as a backslash sequence so it is allowed inside a JSON string, for example a newline written as \n.
- Unescape
- The reverse of escaping: decoding backslash sequences back into the raw characters they represent.
- JSON string
- A run of characters wrapped in double quotes, with special characters escaped, as defined by the JSON standard.
- Control character
- A character with a code point below U+0020 (such as tab or newline) that may not appear raw inside a JSON string.
- Unicode escape
- The form \uXXXX, four hex digits that encode a character by its code point, used for control characters and any character.
- RFC 8259
- The Internet standard document that defines the JSON data format, including exactly which characters a string must escape.
- Surrogate pair
- Two \u escapes used together to represent a single character outside the Basic Multilingual Plane, such as most emoji.
- Serialization
- The general process of converting a value in memory, such as a string or object, into a text format like JSON for storage or transmission.
Frequently asked questions
What does it mean to escape a JSON string?
Escaping rewrites text so it is valid inside a JSON string. Characters that are not allowed raw, such as double quotes, backslashes, newlines and tabs, are replaced with backslash sequences like \", \\, \n and \t. The result can be pasted between quotes in a JSON document without breaking the parser.
How do I unescape a JSON string?
Switch to Unescape mode and paste the escaped string. The tool decodes every backslash sequence back to the character it stands for, so \n becomes a real newline and \" becomes a plain double quote. You can paste the value with or without its surrounding double quotes.
Does this tool send my text anywhere?
No. All escaping and unescaping happens in your browser using the built-in JSON.stringify and JSON.parse functions. Your text is never uploaded to a server, so it is safe to use with private or sensitive data.
Should the output include the surrounding double quotes?
It depends on where you are pasting. If you are inserting the value into an existing pair of quotes, leave the quotes off (the default). If you need a complete JSON string value on its own, tick "Wrap output in double quotes" to include them.
Why does my input get rejected in unescape mode?
Unescape uses a real JSON parser, so the text must be a valid JSON string. A common cause is an unescaped double quote or a lone backslash in the middle of the text. Escape those first (a quote as \", a backslash as \\) and try again, or check you are not in the wrong mode.
Is JSON escaping the same as URL or HTML escaping?
No. Each format has its own rules. URL encoding uses percent escapes like %20, and HTML uses entities such as the ampersand. JSON escaping uses backslash sequences such as \n and \". Use the encoder that matches the format you are targeting.
How do I escape a JSON string in Python or Java?
Python uses json.dumps(text) to escape and json.loads(text) to unescape. Java projects typically use a library such as Jackson (objectMapper.writeValueAsString) or Gson. All of them follow the same JSON standard, so a string escaped in this browser tool will parse correctly in any of them.
Why do backslashes get doubled when I escape a Windows file path?
A single backslash is not allowed raw inside a JSON string, so each one is escaped as two backslashes (\\). A path like C:\Users\me becomes C:\\Users\\me. This is correct and expected, JSON.parse turns each \\ pair back into one backslash when you unescape it.
Does JSON escaping handle emoji and other Unicode characters correctly?
Yes. Emoji and other characters outside the Basic Multilingual Plane are represented as a surrogate pair, two \u escapes in sequence. JSON.stringify creates this pair automatically and JSON.parse reassembles it back into the original character, so round-tripping emoji through escape and unescape is safe.
Do I need to escape the forward slash in JSON?
No, escaping a forward slash as \/ is allowed but never required. Some tools escape it anyway, historically to make embedding JSON inside HTML script tags safer, but a plain unescaped / is equally valid JSON and this tool leaves it unescaped by default.