Escape strings for JSON safety
Turn arbitrary text into a JSON string literal (or back). Handles quotes, backslashes, control chars, and Unicode surrogate pairs.
"She said \"hello\" 👋\nAnd then \\ a backslash"
How to escape / unescape JSON strings
Use this when you need to embed user text inside a JSON payload (or extract it back). The tool runs JSON.stringify for escape and JSON.parse for unescape — strictly RFC 8259.
- 01
Pick a mode
Escape wraps text into a valid JSON string literal. Unescape turns a JSON string literal back into raw text.
Inputs parse through the native
JSON.parsereviver chain — strict RFC 8259. Any syntax error returns line and column for the exact offending byte.escapeunescapeRFC 8259JSON.parsestrictmode · rawswap · RFC 8259escape ↔ unescape
loaded · parsed RFC 8259RFC 8259 · ready - 02
Paste your text
For escape: any text — quotes, backslashes, newlines, emoji all work. For unescape: a complete JSON string (including the quotes).
quotesnewlinesemojiinputrawShe said "hi" 👋
loaded - 03
Auto-conversion
Escape:
"→\\", newline →\\n, emoji → surrogate pair\\ud83d\\udc4b.Large documents stream through a
useMemowith stable hashing so options re-apply instantly — no full re-parse if only formatting changes.safeUnicodememoisedinstantdiff-friendlyoutput · renderedescaped · ready"She said \"hi\" \ud83d\udc4b"
rendered · livediff-friendly - 04
Embed or transmit
Use the escaped value inside a JSON document, HTTP body, log line, or env var. Swap mode to round-trip back to plain text.
Download is a
Blobwithapplication/json; copy uses the Async Clipboard API. Both round-trip identically to what the page rendered.round-tripclipboardblob.jsonzero-networkready · copiedembed · done{"msg":"...escaped..."}shipped · ready to shipsuccess
Production-grade JSON, the right way
Stick to RFC 8259
Strict JSON has no NaN, Infinity, comments, or trailing commas. If you need those, look at JSON5 or JSON Repair.
Preserve key order for diffs
JavaScript preserves insertion order, but two parsers shouldn’t be assumed equal. Use Sort JSON Keys before diffing or hashing.
Big integers lose precision
JS numbers lose precision past 2^53−1. Transport large IDs as strings or use BigInt.
Escape inside HTML
When inlining JSON inside <script>, escape </ to <\/ so HTML parsing doesn’t close your tag early.
Validate at boundaries
Trust the wire as little as possible. Run incoming JSON through a schema (Zod / Pydantic) before it touches business logic.
Minify in production
Minify removes whitespace; gzip removes redundancy. Together they typically shrink JSON payloads 70–85% over the wire.
When to escape JSON strings
Whenever raw text needs to live safely inside a JSON document.
Embedding in HTML
Quote a JSON string inside a <script> tag without breaking parsing.
Env vars
Inject JSON payloads as environment variables without quoting nightmares. Pairs perfectly with sort-keys + diff for review-friendly fixtures in CI. Whitespace-only churn disappears and reviewers see real changes, which keeps PR comments focused on logic rather than indentation.
cleaner PR diffsLog line embedding
Drop user text into structured logs without breaking JSON parsing downstream. Handles emoji and non-ASCII via UTF-8 throughout — your data survives copy-paste between editors, terminals, and IDEs. Combining marks and ZWJ sequences come out the other side intact.
RFC 8259 validAPI request bodies
Take a string with quotes (title: 'Some "quoted" phrase') and produce a valid request body.
Test fixtures
Generate fixture strings that won't break your suite's JSON loader. Streams large documents without a server round-trip — privacy stays in the tab. Heavy parsing runs through useMemo so even 5 MB payloads keep the editor responsive.
schema-friendlyDecode escaped strings
Reverse — get the underlying plain text from a captured JSON string. Output is byte-stable: same input plus same options always produces identical bytes, ideal for content-addressed caches and snapshot tests. Downloads ship with the application/json MIME so editors apply syntax highlighting.
production-readyFrequently asked questions
Something missing?
Tell us what you need. We ship the top requests every two weeks.