CruxDevCruxDev Tools Prompts
dev Utility • Zero-Server Privacy • 100% Client-Side

JSON Escape / Unescape

Escape raw text into a JSON string literal, or unescape one back — newlines, quotes, and unicode handled.

Overview

Escapes raw text into a valid JSON string literal — surrounding quotes included — and unescapes such a literal back into raw text. When an API rejects a payload because a string contains a raw newline or an unescaped quote, this is the fix.

How It Works

Pick the direction with the toggle: Escape → JSON string turns whatever you paste into a quoted, escaped literal; Unescape ← JSON string does the reverse and even accepts input without the surrounding quotes. The result updates live, and invalid escapes in unescape mode surface JSON.parse's own error message.

Step-by-Step Usage Guide

  1. Choose Escape or Unescape with the toggle.
  2. Paste the raw text or the escaped literal.
  3. Read the converted result — in unescape mode, quotes around the input are optional.
  4. Copy the result into your code, config, or payload.

Technical Specifications & Standards

Escaping is delegated to JSON.stringify, the specification's own encoder: backslash and double quote get a backslash, newline, carriage return, tab, backspace, and form feed get their short forms, and the remaining control characters become \u00XX. Unescaping is JSON.parse — the specification's decoder — which additionally understands \/ and \uXXXX four-digit forms. Non-ASCII characters such as é or 中文 pass through literally in both directions; the tool never rewrites them to \uXXXX.

Targeted Use Cases

  • Embedding user-supplied text inside a JSON payload without the first quote or newline breaking the string.
  • Decoding \n-escaped strings copied out of API logs or stack traces.
  • Preparing single-line string values for JSON config files, where a literal line break would be invalid.
  • Round-tripping generated JSON snippets to check nothing was double-escaped.

Notes & Gotchas

  • Escape output includes the surrounding double quotes, because a JSON string literal is defined to have them. Strip them if your context supplies its own quoting.
  • Unescape accepts input with or without surrounding quotes — anything that does not start with one is wrapped for you before parsing.
  • Unicode is preserved as-is: é stays é rather than becoming \u00e9. If you need ASCII-only output, escape it in a separate step.
  • Errors are JSON.parse's own messages, shown inline with a ✗ prefix — an invalid \u sequence is the usual culprit in pasted log fragments.

Frequently Asked Questions

Which characters get escaped?

Backslash, double quote, newline, carriage return, tab, backspace, form feed, and the remaining control characters as \u00XX — exactly the JSON specification's minimum set.

Why does the output start and end with quotes?

A JSON string literal includes its delimiters, and the value is produced by JSON.stringify. Remove them if the string is going into an already-quoted context.

Is this the same as URL encoding?

No. URL encoding is for query strings and uses %XX sequences; JSON escaping is for string values inside JSON documents and uses backslash sequences.

Is my text uploaded?

No. Both directions run in your browser using the built-in JSON functions.