JSON Escape / Unescape
Escape raw text into a JSON-safe string, unescape a JSON string back to plain text, or minify and validate a whole JSON document. Backslashes, quotes, newlines, tabs and control characters are handled to the letter of the JSON spec. Everything runs in your browser — nothing is uploaded.
What each mode does
| Mode | What it does | Example |
|---|---|---|
| Escape | Turns raw text into an escaped JSON string — backslashes, double quotes, newlines, tabs and other control characters are replaced with their JSON escape sequences so the text can be dropped safely inside a JSON string. | a"b → a\"b |
| Unescape | Reverses escaping — reads a JSON-style escaped string (with or without its surrounding quotes) and returns the original text, resolving \n, \t, \", \\, \uXXXX and the rest. | caf\u00e9 → café |
| Minify / Validate | Parses a whole JSON document and re-emits it with every non-essential space and newline removed. If the JSON is invalid it reports the parser error instead — so it doubles as a validator. | { "a": 1 } → {"a":1} |
Escape options
| Option | What it does | Example |
|---|---|---|
| Wrap in double quotes | Adds the surrounding "…" so the output is a complete JSON string value, not just the escaped contents. | hi → "hi" |
| Escape forward slash (/ → \/) | Optional. Some encoders escape the forward slash to keep a JSON block from ending an HTML script element early. Off by default because it is not required by the JSON spec. | a/b → a\/b |
| Escape non-ASCII (\uXXXX) | Converts every character above the ASCII range to a \uXXXX escape, producing pure-ASCII output. Off by default, because JSON strings may contain UTF-8 characters directly. | é → \u00e9 |
Examples
| Mode | Input | Output |
|---|---|---|
| Escape | C:\Users\me | C:\\Users\\me |
| Escape | Say "hello" | Say \"hello\" |
| Escape (slash on) | 1/2 and 3/4 | 1\/2 and 3\/4 |
| Unescape | caf\u00e9 | café |
| Unescape | \"quoted\" | "quoted" |
| Minify | { "a": 1, "b": [ 1, 2 ] } | {"a":1,"b":[1,2]} |
Which JSON escape sequences are used
JSON defines a small, fixed set of two-character escape sequences plus the general
\uXXXX form for anything else. Escape mode uses exactly these, and unescape mode
understands all of them:
| Character | Escaped as |
|---|---|
Double quote " | \" |
Backslash \ | \\ |
| Newline | \n |
| Carriage return | \r |
| Tab | \t |
| Backspace | \b |
| Form feed | \f |
Forward slash / (optional) | \/ |
| Other control / (optional) non-ASCII | \uXXXX |
Why you need to escape strings for JSON
A JSON string is delimited by double quotes, so a raw double quote inside the text would end
the string early and corrupt the document. The backslash is reserved to introduce escape
sequences, so it too must be doubled. And because the JSON grammar forbids literal control
characters, a value that contains an actual line break or tab — a Windows file path, a
formatted log line, a snippet of source code — has to have those characters converted to
\n, \t and friends before it can be stored. Skipping this step is one
of the most common causes of “unexpected token” parse errors, especially when text is glued
into a JSON template by hand or by string concatenation instead of a proper serializer.
Escaping, minifying and validating are different jobs
It is easy to conflate these because they all involve JSON, but they operate at different levels. Escaping transforms a single value so it is safe inside quotes. Minifying takes a complete, already-valid JSON document and strips whitespace to shrink it for transport — it never changes the data, only its formatting. Validating simply answers whether a document parses at all. This tool keeps them as separate modes on purpose: reach for Escape/Unescape when you are moving a piece of text in or out of a JSON string, and for Minify/Validate when you already have a JSON structure and want it compact or checked. If instead you want to pretty-print JSON with indentation, the JSON Formatter is the tool for that.
Reading double-escaped data
When data passes through several systems it can pick up more than one layer of escaping — a
JSON string whose contents are themselves an escaped JSON string, so a single quote shows up as
\\\" and a newline as \\n. Running Unescape once peels off one layer;
run it again on the result to peel off the next. Because the unescaper also strips a single pair
of surrounding quotes if it finds them, you can paste a complete string literal straight from a
log or a debugger and get the readable text back without hand-editing the quotes first.
Frequently asked questions
- What does it mean to “escape” a JSON string?
- Inside a JSON string a few characters have a special meaning and cannot appear literally: the double quote closes the string, and the backslash starts an escape sequence. Control characters such as a newline or a tab are also not allowed raw. Escaping replaces each of these with a safe two-character sequence — a newline becomes \n, a tab becomes \t, a quote becomes \" and a backslash becomes \\ — so the whole piece of text can be placed inside a JSON string without breaking the document. This tool does exactly that transformation, and can reverse it.
- When would I need to escape or unescape JSON?
- The most common case is embedding one piece of data inside another: putting a code snippet, a file path (full of backslashes), an HTML fragment or a multi-line message into a JSON payload for an API, a config file or a log entry. You escape it going in and unescape it coming out. Unescaping is also handy for reading a value that has been “double-escaped” — for example a JSON string that itself contains encoded JSON, which is easy to end up with when data passes through several systems.
- What is the difference between escaping and minifying?
- Escaping works on a single string value — it makes arbitrary text safe to sit inside a pair of JSON quotes. Minifying works on a whole JSON document — it parses the structure and re-prints it with no unnecessary whitespace to make it as small as possible for transport. They are different jobs: use Escape when you have raw text you want to insert into JSON, and Minify when you already have valid JSON and just want to compress it. Minify mode also validates, reporting the exact parser error if the JSON is malformed.
- Should I turn on “escape forward slash” or “escape non-ASCII”?
- Usually no. The JSON specification does not require the forward slash to be escaped, and JSON strings are allowed to contain UTF-8 characters like accents and emoji directly, so the default output is valid and readable. Turn on “escape forward slash” only when you are embedding JSON inside an HTML script element and want to stop the data from accidentally ending that element early. Turn on “escape non-ASCII” only when a downstream system requires plain 7-bit ASCII — the output stays valid JSON either way, just longer.
- Does unescape handle emoji and other characters outside the basic range?
- Yes. Characters beyond the basic multilingual plane — most emoji, for instance — are represented in JSON as a surrogate pair of two \uXXXX escapes. The unescaper resolves each half and the two code units combine back into the single original character, so “\ud83d\ude00” round-trips cleanly to 😀. Escaping with the non-ASCII option turned on produces the same surrogate-pair form.
- Is my data sent anywhere?
- No. Every operation runs in your browser with plain JavaScript — the text you paste never leaves your device and nothing is stored. That makes the tool safe for tokens, internal payloads, private configuration and any other sensitive data, and it works offline once the page has loaded.