JSON String Escape / Unescape

Turn any text into a valid JSON string, or read a JSON string back into plain text. It runs in your browser: the text you paste never leaves your device.

Direction

Your text stays in your browser. This page sends it nowhere and makes no network request while you type.

What is escaped

A JSON string is written between double quotes. All characters may sit inside the quotes except the ones that must be escaped: the quotation mark, the backslash and the control characters U+0000 through U+001F [1]. Common characters have short forms; the rest of the controls use \u00XX.

" → \" \ → \\ line break → \n tab → \t carriage return → \r other control → \u00XX

Unescape reads the same grammar strictly. It accepts \" \\ \/ \b \f \n \r \t and \uXXXX, joins a surrogate pair into one character, and stops at the first problem with a message that says what is wrong and where.

Example

Input (a quote, a backslash-n typed as two characters, a tab, and non-ASCII): He said "hi"\n café 😀

  1. Escape with quotes: "He said \"hi\"\\n\tcafé 😀"
  2. Escape without quotes, non-ASCII as escapes: He said \"hi\"\\n\tcaf\u00e9 \ud83d\ude00
  3. Unescape either one and you get the input back.

Questions

Does my text leave my device?

No. The page works in your browser and sends nothing anywhere. It makes no network request while you type or paste.

Which characters must be escaped?

The quotation mark, the reverse solidus (backslash) and the control characters U+0000 to U+001F [1]. Everything else may be written as it is. This tool does not escape the forward slash.

What does “non-ASCII as \u” do?

It writes every character outside plain ASCII as \uXXXX. A character outside the Basic Multilingual Plane, such as an emoji, becomes two escapes (a surrogate pair), the 12-character form in the RFC [1].

What if the text has an unpaired surrogate?

Escape always writes it as \uXXXX so the output is valid. Unescape accepts an unpaired surrogate escape but warns you, because software can treat such text differently [2].

How are errors reported?

With what is wrong and where: the line and column of the first problem, such as an unescaped quote, a raw line break, an escape like \x that JSON does not have, or a \u without four hex digits.

Sources

  1. IETF. RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format, section 7 Strings. Accessed .
  2. IETF. RFC 8259, section 8.2 Unicode Characters. Accessed .

Last updated .