Escape and unescape a JSON string

Turn text into a JSON string and back, with optional \uXXXX for non-ASCII. Nothing leaves your browser.

How it works

  1. Paste your text or your JSON string
  2. Choose escape or unescape
  3. Copy the result

What escape writes

Escape turns any text into the inside of a JSON string, so it can sit between double quotes in a JSON document or a line of code. A double quote becomes \" and a backslash becomes \\. Line breaks, tabs, backspaces and form feeds become \n, \r, \t, \b and \f, so a Windows line break turns into \r\n. Every other control character below U+0020 becomes a \u escape with four hex digits, for example \u0001, and so do the line and paragraph separators U+2028 and U+2029, which some older JavaScript engines reject inside a string. A forward slash is left alone. Turn on Wrap in quotes to add a " at each end and get a complete JSON string.

Non-ASCII characters

By default letters such as é and symbols such as ✓ are written as they are, which is valid JSON in a UTF-8 file. Turn on Escape non-ASCII as \uXXXX when the receiving system needs plain ASCII. Then every character above U+007E is written as \u followed by four lowercase hex digits. Characters outside the first 65,536, such as emoji, are written as two escapes (a surrogate pair), for example 😀 becomes \ud83d\ude00. An unpaired surrogate half in your text is always escaped, so the result can be read back.

What unescape accepts

Unescape takes a JSON string with or without its surrounding double quotes. If the text, ignoring spaces and line breaks around it, starts and ends with a quote, those two quotes are removed. A final quote that is itself escaped, as in abc\", is treated as part of the text. It understands \" \\ \/ \b \f \n \r \t and \uXXXX, and joins a surrogate pair into one character. A real line break or tab typed inside the text is accepted as it is, which is more relaxed than strict JSON. Anything else is reported with a fixed message and a position counted in characters from 1: a backslash followed by an unknown letter, a \u without four hex digits, a lone backslash at the end, or a bare double quote in the middle of the text. The message never repeats your text.

Scope and limits

This page handles one string at a time and does not read or change a whole JSON document; use the JSON formatter for that. Text up to 1,000,000 characters is accepted, and if escaping would make the result longer than 5,000,000 characters you get a message instead. The work happens in your browser. The text is not uploaded or stored; only your choices are remembered.

Frequently asked questions

Why does my pasted text show an error at a backslash?

A backslash must be followed by one of \ " / b f n r t or u and four hex digits. A path such as C:\temp has a \t, which is a tab, but C:\users has \u and no hex digits, which is the error. Escape the text first and its backslashes are doubled.

Should I turn on Wrap in quotes?

Turn it on when you need a complete JSON string value, for example to paste after a key. Leave it off when you are placing the result between quotes that are already in your code or document.

Does it change the forward slash?

No. A forward slash is written as it is. On the way back, \/ is understood and becomes a plain /.

Why do emoji become two escapes?

JSON escapes work on 16-bit units. A character outside the first 65,536 is stored as two units, so it is written as two \u escapes, a surrogate pair. Unescape joins them back into one character.

Is my text uploaded?

No. It is processed in your browser, in this tab, and no server receives it. Your choices are saved in this browser, the text is not.