Lintify Logo
Lintify
Validators & Formatters

JSON Escape / Unescape

Escape JSON strings for safe embedding in HTML, attributes, or other strings — and unescape them back. Handles quotes, backslashes, new lines, and control characters.

Raw string
1
Escaped output
Output will appear here…

Escape and unescape JSON strings

JSON strings can contain almost any Unicode character, but a small set of characters must be escaped with a backslash to be valid: the double quote, the backslash itself, and the control characters from U+0000 to U+001F (new line, tab, backspace, form feed, and so on). When you need to embed a JSON document inside another string — inside a script tag, inside an HTML attribute, inside a SQL statement — you often need to apply additional escaping on top of the JSON escaping. That is what this tool helps with.

Pick Escape to add the backslashes required for a specific embedding context, or Unescape to remove them. The HTML-safe mode additionally escapes<, >, and & so the result can be safely embedded inside an HTML document without breaking out of the script tag.

JSON escape vs URL encode vs HTML encode

These three forms of escaping are not interchangeable. JSON escaping produces a valid JSON string value — it adds backslashes for characters that are special inside JSON strings. URL encoding (percent encoding) produces something safe to put in a URL. HTML encoding produces something safe to put inside an HTML document. Always pick the form that matches the context you are embedding into.

Unescaping multi-layer escaped strings

It is common to encounter a JSON string that has been escaped more than once — for example, a JSON value that contains a JSON string that contains an HTML string. Each layer of escaping adds another set of backslashes. Run the unescape function multiple times to peel off one layer at a time. Stop when the output stops changing. This is a common debugging step when working with webhooks that wrap payloads in multiple layers of JSON.

What about non-ASCII characters?

The JSON spec allows but does not require non-ASCII characters to be escaped. Most modern JSON serializers write UTF-8 directly — they emit the literal é, あ, or 🎉 rather than the\u00e9 form. Lintify follows that convention and does not escape non-ASCII characters by default. If you need pure ASCII output (for example, for a legacy transport that cannot handle multi-byte characters), post-process the output to convert every character above U+007F to its \uXXXXform.

Frequently asked questions

Common questions about the Escape tool.

Which characters does JSON escaping handle?
The JSON spec requires escaping the double quote, backslash, and the control characters from U+0000 to U+001F. Lintify also offers an HTML-safe mode that escapes <, >, and & so the result can be embedded inside an HTML document without breaking out of the script tag.
What is the difference between JSON escape and URL encoding?
JSON escaping produces a valid JSON string value (escaping quotes and control chars). URL encoding (percent encoding) produces something safe to put in a URL. They are not interchangeable — use the right one for the context you are embedding into.
Why does my escaped JSON still have quotes in it?
Escaping only adds a backslash before characters that need it. It does not remove the quotes that wrap the JSON string itself. If you want the result without surrounding quotes, use the JSON Stringify tool with a custom wrapper, or strip the outer quotes manually after escaping.
Is escaping the same as serialization?
Almost. Serialization (JSON.stringify) takes a JavaScript value and produces a JSON string. Escaping takes an already-serialized string and adds the backslashes required for a specific embedding context. In most workflows you serialize once, then escape if you need to embed the result somewhere unusual.
Can I unescape a string that was double-escaped?
Yes. Run the unescape function multiple times — each pass removes one layer of backslashes. Stop when the output stops changing. This is common when JSON has been stored inside another JSON string and then re-escaped for transport.

Related tools