RFC 8259 · Unicode · safe for embedding

Escape strings for JSON safety

Turn arbitrary text into a JSON string literal (or back). Handles quotes, backslashes, control chars, and Unicode surrogate pairs.

JSON Escape / Unescape Workspace
Input size
42 B
2 lines
Output size
48 B
JSON string
Mode
escape
plain → escaped
Status
OK
RFC 8259
Mode
input · plain text
output · JSON-escaped
"She said \"hello\" 👋\nAnd then \\ a backslash"
Quick Start

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.

  1. 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.parse reviver chain — strict RFC 8259. Any syntax error returns line and column for the exact offending byte.

    escapeunescapeRFC 8259JSON.parsestrict
    mode · rawswap · RFC 8259
    escape ↔ unescape
    loaded · parsed RFC 8259RFC 8259 · ready
  2. 02

    Paste your text

    For escape: any text — quotes, backslashes, newlines, emoji all work. For unescape: a complete JSON string (including the quotes).

    quotesnewlinesemoji
    inputraw
    She said "hi" 👋
    loaded
  3. 03

    Auto-conversion

    Escape: " → \\", newline → \\n, emoji → surrogate pair \\ud83d\\udc4b.

    Large documents stream through a useMemo with stable hashing so options re-apply instantly — no full re-parse if only formatting changes.

    safeUnicodememoisedinstantdiff-friendly
    output · renderedescaped · ready
    "She said \"hi\" \ud83d\udc4b"
    rendered · livediff-friendly
  4. 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 Blob with application/json; copy uses the Async Clipboard API. Both round-trip identically to what the page rendered.

    round-tripclipboardblob.jsonzero-network
    ready · copiedembed · done
    {"msg":"...escaped..."}
    shipped · ready to shipsuccess
Pro tips

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.

Use Cases

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.

10× faster to scan

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 diffs

Log 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 valid

API request bodies

Take a string with quotes (title: 'Some "quoted" phrase') and produce a valid request body.

round-trip safe

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-friendly

Decode 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-ready
FAQ

Frequently asked questions

Yes. Astral characters become surrogate pairs (\ud83d\udc4b for 👋), and unescape decodes them back to the original character.
Escape converts newline → \n, tab → \t, etc. Unescape reverses.
Yes — unescape returns the underlying plain text.
JSON escaping is specific to JSON.parse syntax. Use URL/HTML escapers for those contexts.
No. All processing runs locally.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!