JSON Escape / Unescape
Escape a string for safe embedding in a JSON value, or unescape a JSON-encoded string back to plain text.
工具代码会在浏览器中处理所选文件和输入内容,不会将其提交给 TOOLGRID 的处理接口。 TOOLGRID 只衡量工具使用情况,不记录你输入的内容。
- 不上传工具输入至 TOOLGRID
- 不登录
- 复制前先检查
Loading tool…
这个工具能做什么
In-browser JSON escape / unescape via JSON.stringify and JSON.parse. Optional outer-quote inclusion. Both directions supported.
Paste any text and the tool produces a JSON-safe escaped version: " becomes \", \ becomes \\, newlines become \n, tabs become \t, and any non-ASCII characters that the JSON spec considers escapable get escaped. The output is ready to drop directly inside a JSON string value.
Toggle "Include outer quotes" on if you want the full JSON string literal (with leading and trailing ") ready to paste into a JSON document as-is. Off (default) gives you the inside of the string, which is what you usually want when concatenating or templating.
Switch to Unescape mode to go the other direction: paste a JSON-escaped string (with or without the outer quotes) and the tool decodes the escape sequences back to the original characters — useful when reading webhook payloads, copy-pasting strings out of JSON logs, or inspecting JSON-encoded values from a database.
All processing uses JavaScript's built-in JSON.stringify / JSON.parse — the same rules as every JSON library and browser. Tool code processes selected files and entered content in your browser and does not submit them to a TOOLGRID processing endpoint. Pair with JSON Formatter when the surrounding document needs pretty-printing, or HTML Escape when the text will eventually be rendered as HTML.
这个工具适合解决什么问题
Webhooks expect a JSON body where the message text is a JSON string value. Multi-line messages or messages containing quotes break the JSON if pasted raw — escape them here first.
When sending a GraphQL query as a JSON body, the query string itself is a JSON value. Backslashes, quotes, and newlines inside the query need to be JSON-escaped — drop the raw query in to get the safe form.
Many systems store complex strings as JSON-encoded values (e.g., error stack traces with quotes). Paste the encoded form into Unescape mode to recover readable text.
依赖结果前需要检查什么
- Performance and maximum practical input size depend on browser memory, device speed, and the structure of the input.
- Review the generated result before replacing or publishing an original file.
如果还需要校验、转换或复用结果,可以继续打开相近的浏览器本地工具。
如何使用
01使用场景
Webhooks expect a JSON body where the message text is a JSON string value. Multi-line messages or messages containing quotes break the JSON if pasted raw — escape them here first.
When sending a GraphQL query as a JSON body, the query string itself is a JSON value. Backslashes, quotes, and newlines inside the query need to be JSON-escaped — drop the raw query in to get the safe form.
Many systems store complex strings as JSON-encoded values (e.g., error stack traces with quotes). Paste the encoded form into Unescape mode to recover readable text.
When an environment variable needs to hold a JSON document (Vercel, Docker, Kubernetes), the variable value is a string and the JSON inside it must be self-consistent. Escape the JSON document with outer quotes off, then wrap with single quotes in your env file.
When sharing code samples in a JSON-based API (issue tracker, documentation system), the code becomes a JSON string. Escape converts your <code>\n</code>-separated code into a single-line escaped form that round-trips cleanly.
使用技巧
- 01JSON escape ≠ URL encode ≠ HTML escape
JSON escape handles characters that would break a JSON string value (<code>"</code>, <code>\</code>, control chars, newlines). URL encoding handles URL-reserved characters (<code>?</code>, <code>&</code>, spaces). HTML escape handles HTML-reserved characters (<code><</code>, <code>></code>, <code>&</code>). Pick the encoding that matches the context the string will live in.
- 02Outer quotes matter for paste-and-go
With outer quotes ON, the output is a complete JSON string literal you can paste directly into a JSON document. With OFF, you get the inside of the string — useful for template-string concatenation in code where you'll add quotes yourself.
- 03Unicode characters above U+FFFF use surrogate pairs
JSON encoding of emoji and rarely-used scripts uses the <code>\uHHHH\uHHHH</code> surrogate-pair convention. Most JSON parsers handle this correctly; if a downstream system rejects surrogates, that's a parser bug — not a JSON spec issue.
- 04Round-tripping is loss-free
Escape then immediately Unescape should return the exact original text. If it doesn't, the unescape input is malformed (typically a stray <code>\</code> at the end, or unclosed escape sequence). Watch for this when copy-pasting from formatted log output that may have wrapped lines mid-escape.
常见问题
02What characters does JSON escape encode?
Per the JSON spec (RFC 8259): the quote character <code>"</code> becomes <code>\"</code>; backslash <code>\</code> becomes <code>\\</code>; control characters (U+0000 through U+001F) become <code>\u00XX</code> escapes; common ones have shortcuts: newline → <code>\n</code>, tab → <code>\t</code>, carriage return → <code>\r</code>, form feed → <code>\f</code>, backspace → <code>\b</code>. All other Unicode characters pass through unchanged (the spec allows raw UTF-8 in JSON strings).
What's the difference between Escape and Unescape modes?
Escape takes plain text and produces a JSON-safe version (e.g., <code>he said "hi"</code> → <code>he said \"hi\"</code>). Unescape goes the opposite direction. They're inverses: escape→unescape should give you back the original.
When should I include the outer quotes?
Include them (toggle ON) when you'll paste the result directly into a JSON document as a complete value. Exclude them (default OFF) when the output will be concatenated or templated into code that adds the quotes itself.
Is JSON escape the same as JavaScript string escape?
Very similar but not identical. JavaScript strings allow single quotes and a few escapes (like <code>\v</code> for vertical tab and <code>\x41</code> for ASCII) that JSON doesn't. Stick to JSON escape when the destination is JSON; use a JavaScript-specific encoder when the destination is JS source code.
What about HTML or URL contexts — can I use this output there?
No. JSON-escaped text is safe inside a JSON string; it's NOT safe in HTML (where <code><</code> and <code>></code> need entity encoding) or URLs (where reserved characters need percent-encoding). If the JSON value will eventually be rendered as HTML or used in a URL, apply additional layer-appropriate encoding on top.
Is my input sent to a server?
JSON escape/unescape uses the browser's built-in <code>JSON.stringify</code> and <code>JSON.parse</code>. Tool code processes selected files and entered content in your browser and does not submit them to a TOOLGRID processing endpoint. Browser-local processing avoids a TOOLGRID upload path, but it is not a blanket security guarantee.
Why does Unescape fail on my input?
Most common causes: (1) the input has unbalanced escape sequences (a stray <code>\</code> at the end), (2) the input has unescaped control characters that the JSON spec doesn't allow, (3) the input is just plain text without any actual escapes (try running it through Escape first to see what valid escaped form looks like).

