JSON Escape / Unescape
Escape and unescape JSON strings
JSON Escape / Unescape tool
JSON Escape / Unescape: key facts
- What it does
- Escape and unescape JSON strings
- Category
- Developer Tools
- Cost
- Free, with no account, sign-up, or install.
- Your data
- Runs entirely in your browser — the files and text you enter are never uploaded to a server.
- Last reviewed
- . Report an incorrect result.
What this tool is for
Embedding one piece of JSON inside another — or stuffing a multi-line string into a single JSON value — breaks the moment a quote or newline is taken literally. JSON Escape converts a raw string into its safely escaped form, and reverses the process when you need the original back.
Developers hit this whenever a string has to travel through a JSON field that is itself a string: storing a JSON snippet as a value, pasting a code block into a config, or preparing a multi-line message for an API. Escape mode turns the dangerous characters into their backslash equivalents; unescape mode restores them so you can read the content as it was written.
How to use the JSON Escape / Unescape
- Choose your direction with the Escape / Unescape toggle.
- In Escape mode, paste the raw string you want to make JSON-safe; in Unescape mode, paste the escaped string.
- Read the converted output as you type — quotes, backslashes, and whitespace characters are handled automatically.
- Click Copy to grab the result for your JSON value or your editor.
Escaping for embedding, not for validity
This converts a block of text into the escaped form needed to sit inside a JSON string, and reverses the process. Backslashes are doubled first — order matters, since escaping them after the other substitutions would double the escapes already inserted — then quotes, newlines, carriage returns, tabs, form feeds, and backspaces are replaced with their two-character sequences.
The distinction between this and formatting is worth being clear about. A formatter operates on a JSON document; this operates on the contents of a single string within one. It is what you need when embedding a code snippet, a log excerpt, an HTML fragment, or another JSON document inside a JSON string value.
Unescaping performs the reverse, turning the sequences back into the characters they denote, which is how you recover readable text from a value that has been escaped one or more times.
- A literal double quote becomes the two characters backslash and quote.
- A real newline becomes the two characters backslash and n.
- Escaping a JSON document to embed it inside another produces doubled backslashes throughout, which is why nested payloads become unreadable quickly.
What the JSON Escape / Unescape gets right
- It handles the full set of characters that break JSON strings — quotes, backslashes, newlines, carriage returns, tabs, form feeds, and backspaces — not just quotes.
- The single Escape/Unescape toggle works both directions, so you can round-trip a value without switching tools.
- It processes any input without imposing a format, so you can escape a whole code block or a one-line string equally.
- Conversion is local to your browser, keeping whatever you paste private.
Nesting, and characters that must be escaped
The specification requires escaping for exactly three things: the double quote, the backslash, and control characters below U+0020. Everything else is optional. The forward slash may be escaped and usually is not, though escaping it is a common defensive habit when embedding JSON inside a script tag, where the sequence that closes the tag would otherwise terminate it early.
Unicode above the control range can be sent literally in UTF-8 or escaped as a four-hex-digit sequence, and both are valid. Characters outside the basic multilingual plane — many emoji among them — require a surrogate pair of two such sequences, which is why an emoji sometimes appears as two escapes rather than one.
The practical hazard is double-escaping. Each round of embedding doubles the backslashes, so a value escaped twice contains four backslashes where the original had one, and unescaping the wrong number of times leaves data subtly corrupted. Where a payload has to travel through several layers, escaping once and encoding the result in base64 is usually more robust than nesting escapes.
Frequently Asked Questions
When do I need to escape a string for JSON?
Whenever a string value contains characters that have special meaning in JSON — most commonly double quotes and backslashes, or literal line breaks and tabs. Escaping them lets the string sit safely inside a JSON value without breaking the surrounding structure.
What characters does escaping affect?
Backslash, double quote, newline, carriage return, tab, form feed, and backspace are converted to their backslash escape sequences (\\, \", \n, \r, \t, \f, \b). Unescape mode converts those sequences back into the original characters.
Is escaping the same as encoding?
No. Escaping prepares a string for safe inclusion inside JSON by backslash-escaping special characters. Encoding schemes like Base64 or URL encoding serve different transport needs — use a dedicated encoder for those.
Why did my escaped string come back wrong after unescaping?
Unescape expects input that was actually escaped — sequences like \n and \". If you unescape a string that contains a literal backslash that was never an escape sequence, the result can differ from what you expect. Make sure you are reversing genuinely escaped text, not raw input with stray backslashes.