JSON string escaping, minus the backslash soup

A JSON string lives between double quotes and plays by strict rules: a literal quote must become \, a backslash doubles up, and control characters like newlines and tabs must be written as \n and \t. Paste raw text containing any of those into a JSON document unescaped and the whole payload fails to parse — usually somewhere far away from the actual mistake.

This trips people most when embedding text into API payloads, environment variables, config files and code. The escaping rules are exactly the ones JSON.stringify applies, which is what this tool runs under the hood. Note that escaping is a different job from validating: if you need to check whether a whole JSON document is well-formed, the JSON formatter at /json-formatter is the right tool — this one is for the contents of individual strings.

Open the free JSON Escape / Unescape — no signup, runs entirely in your browser.

How to use it

  1. Pick Escape for raw text going into JSON, or Unescape for string contents coming out.
  2. Paste your text — unescape accepts input with or without the surrounding quotes.
  3. Copy the result; escape mode excludes the surrounding quotes unless you tick the checkbox.

Why this one

  • Exact JSON.stringify semantics on escape, exact JSON.parse semantics on unescape — no hand-rolled surprises.
  • Raw pastes like hello\nworld just work: unquoted input is auto-wrapped before parsing.
  • Helpful failures: input that is valid JSON but not a string (123, true, [1]) says so, and literal line breaks get pointed out by name.
  • Unicode and emoji safe, including the awkward lone-surrogate cases that crash naive implementations.

Frequently asked questions

Why does escape mode leave off the surrounding quotes?

Because the common case is embedding text into an existing JSON string, where the quotes are already there. Emitting them would force you to delete two characters every single time. If you actually want the complete string literal — for pasting into code or a standalone document — tick the quotes checkbox and they are included.

Do forward slashes need escaping in JSON?

No. JSON allows an optional escaped form for the forward slash, and some encoders emit it, but a bare slash is perfectly valid inside a string. This tool follows JSON.stringify, which leaves slashes alone.

Why does unescaping 123 or [1] fail when both are valid JSON?

Because they are valid JSON values, not valid JSON strings. This tool unescapes the contents of a string, so after parsing it checks the result really is text. A number, boolean, array or object gets a clear error telling you to paste string contents instead — silently returning them would hide a paste mistake.