Prepare the contents of a JSON string
Turn ordinary text containing quotes, newlines and backslashes into something that can be embedded inside a JSON string.
Guide
The escape tool covers three families — HTML entities, JSON strings and Unicode \u — each with an encode and a decode direction. HTML decoding uses the text content of a DOMParser result rather than executing any script; JSON unescaping builds a JSON string and calls JSON.parse; Unicode supports both \uXXXX and \u{XXXXX}.
Updated 2026-09-102 min read
| Input | Output | Notes |
|---|---|---|
<a&b> |
<a&b> |
Basic HTML entities |
first line\nsecond line unescaped |
Two lines of text | Through JSON.parse |
| 😀 Unicode-encoded | Two \uXXXX sequences |
Non-BMP output is a UTF-16 surrogate pair |
& < > " '; with the full option on, non-ASCII characters are appended as decimal entities.textContent, so no script inside it runs; it is not an HTML sanitiser or a DOM formatting tool.JSON.stringify; the unescape input must not include the surrounding quotes, and an unescaped quote, backslash or literal newline makes JSON.parse fail.\u sequences it matches; it does not handle \xNN, HTML entities or URL %XX.Turn ordinary text containing quotes, newlines and backslashes into something that can be embedded inside a JSON string.
Turn \u4e2d\u6587 from an API log back into readable text.
\u sequences when Unicode-encoded?An emoji usually sits above U+FFFF, and a JavaScript string represents it as a pair of UTF-16 surrogates, so the tool emits two four-digit escapes as implemented.
<script>?No — only the text content of the parse result is taken, and the input is never inserted into the live page for execution.
All escaping and decoding happen locally in the browser; nothing is uploaded and no input is persisted.
Updated 2026-09-10
Escape and unescape HTML entities, JSON strings and Unicode \u sequences