JSON Escape & Unescape
runs in your browserEscape text for use inside a JSON string, decode an escaped string back to plain text, or turn a JavaScript literal into strict JSON.
Quotes, backslashes, newlines, tabs and control characters are escaped so the text can sit inside a JSON string.
Text
Escaped
about this tool
Three related jobs
Escape takes ordinary text and turns it into a valid JSON string: quotes
become \", backslashes double, newlines become \n, tabs become \t. Use it
when you need to embed a block of text — an error message, a template, a private
key — inside a JSON document by hand.
Unescape reverses it, turning a JSON string literal back into the text it represents. This is the one people need most often: a log line contains a deeply escaped payload and you want to read it.
JavaScript to JSON repairs the near-JSON that turns up in real work — an object literal copied out of source code or a browser console, with unquoted keys, single quotes, trailing commas or comments — and produces strict, valid JSON.
The output of JavaScript-to-JSON is strict JSON, so the JSON formatter will accept it and the JSON tree viewer will let you browse it.
Escaping levels, and why they compound
Escaping applied twice is not the same as escaping once. A string that has been
through JSON encoding on its way into a log, and again on its way into a
message queue, arrives as \\\"value\\\" and is unreadable. Unescape once and
you get \"value\"; unescape twice and you get "value". If the output still
looks escaped, it was escaped more than once — run it through again.
ASCII-only output
The escape non-ASCII option rewrites every character above ASCII as a
\uXXXX sequence, so Grüße becomes Gr\u00fc\u00dfe. That is still
exactly the same string to any JSON parser. It is worth having for systems that
mangle UTF-8 in transit, and for making an invisible character visible: a
zero-width space or a non-breaking space is impossible to spot in the original
text and unmistakable as \u200b or \u00a0. Characters above the basic plane,
such as emoji, are written as the two escapes that encode them.
Which characters must be escaped
JSON requires escaping for the double quote, the backslash, and control
characters below U+0020. Forward slash may be escaped as \/ but never has to
be — a legacy of embedding JSON in HTML script tags, and the reason you sometimes
see it in output from PHP.
Single quotes never need escaping in JSON, which is a common mistake carried over from JavaScript, where the quoting rules are different.
Local, as always
The conversion happens in the page. Escaped payloads pulled from logs routinely contain tokens and personal data, so nothing is transmitted.
questions
- How do I read a deeply escaped string from a log file?
- Unescape it, and if the result still looks escaped, unescape again. Escaping compounds: a payload encoded on its way into a log and again into a queue arrives as \\\" and needs two passes to become readable.
- Which characters have to be escaped in JSON?
- The double quote, the backslash, and control characters below U+0020. Forward slash may be escaped but never needs to be, and single quotes never need escaping at all — a common mistake carried over from JavaScript.
- Can it fix a JavaScript object literal with unquoted keys?
- Yes, that is what the JavaScript to JSON mode does. It repairs unquoted keys, single quotes, trailing commas and comments, producing strict valid JSON from an object copied out of source or a browser console.
- What does escaping non-ASCII characters achieve?
- It rewrites every character above ASCII as a \\uXXXX sequence, which is the same string to any parser. It survives systems that mangle UTF-8, and it makes invisible characters such as a zero-width or non-breaking space visible.
- Is my text sent to a server?
- No. Escaping and unescaping run in the page, which matters because escaped payloads pulled out of logs routinely contain tokens and personal data.