Skip to content
Devtoolry

JSON Escape / Unescape

Escape text for use inside a JSON string, or unescape stringified JSON back to readable text. Handles quotes, backslashes, line breaks and Unicode escapes.

Runs in your browser · Nothing uploaded · No sign-up

Something not working, or missing a feature? Send feedback

About the JSON Escape / Unescape

JSON Escape turns any text into the contents of a JSON string by escaping quotes, backslashes, line breaks and control characters. JSON Unescape does the reverse and turns stringified JSON such as "{\"id\":7}" back into readable text, showing it formatted when the result is a JSON object or array.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the JSON Escape / Unescape

  1. Choose Escape to embed text in a JSON string, or Unescape to read a string that was escaped.
  2. Paste the text. For Unescape the surrounding quotes are optional.
  3. Optionally keep the quotes or escape non-ASCII characters as \uXXXX, then copy the result.

Examples

Escape text for a JSON string

Input

He said "hi"
Path: C:\temp\app.log

Result

He said \"hi\"\nPath: C:\\temp\\app.log

Quotes, the line break and the backslashes are escaped, so the result can sit between double quotes in a JSON file.

Unescape a stringified JSON object

Input

"{\"id\":7,\"tags\":[\"a\",\"b\"]}"

Result

{
  "id": 7,
  "tags": [
    "a",
    "b"
  ]
}

The quotes and escapes are removed, and because the result is a JSON object it is shown formatted.

Common mistakes

  • Escaping twice. Escaping text that is already escaped doubles every backslash (\n becomes \\n). Escape once, at the point where the string is created.
  • Single backslashes in paths. C:\temp\new is read as a tab and a line break. Escape the path first, so each backslash is doubled.
  • Pasting a whole JSON document. To embed a document as a string, escape it here. To format a document, use the JSON Formatter: an escaped document is no longer readable as JSON.

Works well with the JSON Escape / Unescape

Frequently asked questions

Which characters are escaped?

Double quotes, backslashes and the control characters (line break, tab, carriage return, backspace, form feed and the rest below U+0020). The forward slash is left alone, because JSON does not require escaping it.

Why do I get an error when I unescape?

The text contains a backslash that does not start a valid JSON escape, such as \d or a Windows path with single backslashes. The error shows the line and column. Double the backslash (\\) or escape the original text first.

How do I unescape JSON that was escaped twice?

Unescape it once, then paste the result in again. Every pass removes one level of escaping, so a string that was stringified twice needs two passes.

What is the difference between this and JSON.stringify?

For a string, JSON.stringify gives the same escapes plus the surrounding quotes. Turn on Surrounding quotes to get exactly that output.