JSON escape and unescape
When you need to drop raw text — a multi-line message, a snippet containing quotes, a log line — into a JSON document, every special character has to be escaped first. This tool converts raw text into a valid JSON string body and decodes escaped strings back to plain text, using the browser’s own JSON engine so the result is spec-correct.
How it works
Escaping wraps your text with JSON.stringify and removes the outer quotes,
leaving just the escaped body. Unescaping wraps your input in quotes and runs
JSON.parse. Because both use the native engine, every rule of the JSON spec is
honoured, including \uXXXX unicode escapes.
| Character | Escaped as |
|---|---|
" (double quote) | \" |
\ (backslash) | \\ |
| newline | \n |
| tab | \t |
| carriage return | \r |
| control / non-ASCII | \uXXXX (where needed) |
Example
Escaping the two-line text:
Hello "world"
Line two
produces the body:
Hello \"world\"\nLine two
Unescaping that body restores the original two lines exactly. Everything runs in your browser — nothing is uploaded.
When you actually need this
The most common situations where JSON escaping becomes necessary:
Embedding strings in a hand-written JSON payload. If you are constructing a JSON body manually — say, a curl command or a REST client request — and your string value contains double quotes or backslashes, you need to escape those before pasting. Otherwise the JSON becomes invalid and the server rejects it.
Storing multi-line content as a JSON value. JSON strings cannot span multiple lines in source. A code snippet, a SQL query, or a log message that contains real newlines must have them replaced with \n before it can live inside a JSON string.
Decoding an escaped string stored in a database or config file. Systems that store JSON-encoded text will hand you back the escaped body; this tool decodes it so you can read or edit the original content.
The difference between “escape body” and “string literal”
This tool returns the escaped body — the content you would put inside the surrounding double quotes in a JSON document. For example, if the raw text is Say "hello", the escaped body is Say \"hello\".
The companion JSON String Escape tool returns a complete JSON string literal, including the outer double quotes: "Say \"hello\"". Use that version when you want a value you can paste directly as a standalone JSON expression.
Edge cases worth knowing
- Unicode and emoji: Characters above the basic ASCII range round-trip correctly. The native serialiser may represent some control characters as
\uXXXXsequences; unescaping resolves them back to the original code point. - Lone surrogates: A string containing an unpaired surrogate code point (rare, but valid in JavaScript) may be represented with a
\uXXXXescape because JSON technically requires paired surrogates. The tool follows the native engine behaviour. - Invalid escape sequences on unescape: Sequences like
\qor a malformed\ucode are rejected with a parser error rather than passed through silently, keeping the output trustworthy.