JSON Escape / Unescape

Escape and unescape JSON strings

Runs in your browserUtility01Formatters & Validators

What is JSON Escape / Unescape?

A JSON string escaper converts arbitrary text into a form you can safely embed as a JSON string value, handling quotes, backslashes, line breaks, and control characters. The reverse direction turns an already-escaped string back into the original text. Both conversions run locally in your browser.

How to use JSON Escape / Unescape

  1. 1Pick a direction: escape or unescape.
  2. 2Paste your content and the result is produced instantly.
  3. 3The escaped output can be dropped straight into a JSON field as its value, with no need to add the surrounding quotes yourself.

How do I do this in code?

Use the tool above for one-off work; for anything you repeat, move it into a script or your project.

// Escape: lean on JSON.stringify, then strip the surrounding quotes
const escaped = JSON.stringify(text).slice(1, -1);

// Unescape
const restored = JSON.parse(`"${escaped}"`);

Frequently asked questions

When do I need to escape a JSON string?+

Whenever you need to embed text that already contains quotes or line breaks, such as a log excerpt, a SQL statement, or another JSON document, as a string value. Skipping the escape step breaks the structure of the outer JSON and the consumer gets a parse error.

Why does unescaping fail?+

The most common cause is a truncated escape sequence, for example copying only part of a \uXXXX code point. The next most common is content that was escaped twice, in which case you need to run the unescape step two times in a row.

Related tools

All tools