Skip to content
Tools

JSON Escape & Unescape (JSON Stringify Online)

Last updated:

JSON escaping turns text, including a whole JSON document, into a string literal: quotes become \", backslashes become \\ and line breaks become \n, so the value can sit inside another JSON string or a line of code. Unescaping does the reverse and, when the result is JSON, formats it, which is how you read a stringified payload from a log or an API field.

Runs in your browser: your text and JSON never leaves your device – nothing is uploaded, logged or stored on a server. How we protect your data

100% in-browserNothing is uploaded

Input

Loading editor…

Paste JSON or any text to escape

or drop a file anywhere in this box. Everything stays in your browser.

Drop a file to load it

Output

Loading editor…

The escaped string appears here

Results update as you type.

How to use the JSON Escape / Unescape

  1. Choose Escape to stringify, or Unescape to reverse it.
  2. Paste the text or JSON into the input, or press Sample data.
  3. Read the result on the right; it updates as you type. Escaped output includes the surrounding quotes, like the return value of JSON.stringify.
  4. Open Options to minify valid JSON first, drop the quotes, or write non-ASCII characters as \uXXXX. In Unescape you can turn off formatting.
  5. Press "Use output as input" to flip direction on the result, then Copy output.

Worked example

A pretty-printed object becomes one JSON string

Input (JSON)

{
  "event": "login",
  "user": { "id": 42 },
  "note": "said \"hi\""
}

Escaped string

"{\"event\":\"login\",\"user\":{\"id\":42},\"note\":\"said \\\"hi\\\"\"}"

The input was minified first (Options turns that off), then every quote got a backslash. The note value already contained escaped quotes, so they gain a second layer, \\\", which is why nested escaping looks noisy. Unescape applies the same steps backwards.

Characters a JSON string must escape

Characters a JSON string must escape
CharacterWritten asNotes
Double quote "\"Required
Backslash \\\Required
Line feed\nRequired: a raw line break inside a JSON string is a syntax error
Tab\tRequired
Carriage return\rRequired; Windows line breaks are \r\n
Other control characters (U+0000 to U+001F)\u00XX, for example \u001fRequired
Forward slash // (or \/)Optional; JSON.stringify leaves it as is
Non-ASCII, such as é or an emojiKept as is, or \u00e9 with the ASCII optionOptional; the escape is valid JSON either way

What "JSON stringify online" means

People use the phrase for two different jobs. One is turning an object into text, which is just minified JSON (the JSON minifier does that). The other is turning that text into a string literal so it can be stored inside another string, which is JSON.stringify applied to text. This page does the second job, and with "Minify valid JSON first" on it matches JSON.stringify(JSON.stringify(obj)) in JavaScript: one line, every inner quote escaped.

Double-encoded JSON in logs and APIs

JSON often ends up as a string inside JSON: a queue message body, a database column, a log line, a field called payload or data. Every layer of that adds backslashes, and a layer applied twice gives sequences like \\\". Unescape peels up to five layers in one go and tells you how many it removed, then formats the JSON that was inside. Numbers keep every digit while it does so.

Text that is not JSON works too: with a bare string such as line1\nline2, Unescape returns the real line break and says the result is plain text.

Putting a newline inside a JSON string

A JSON string cannot contain a raw line break. Write \n where the break should be, or paste the text with its real line breaks into Escape and copy the result. If a parser complains about a "bad control character in string literal", an unescaped line break or tab is the cause, and the JSON validator shows where.

JSON Escape / Unescape FAQ

How do I stringify JSON into a string literal?

Paste it into Escape. The output is what JSON.stringify returns for that text: wrapped in double quotes, with each quote, backslash and line break escaped. With "Minify valid JSON first" on, you get the one-line form that JSON.stringify(JSON.stringify(obj)) produces; turn it off to escape the text exactly as typed, line breaks included.

How do I put a newline in a JSON string?

Use the two characters \n. Typing a real line break inside the quotes makes the JSON invalid. If you have multi-line text, paste it into Escape and the line breaks become \n for you.

How do I beautify an escaped JSON string?

Paste it into Unescape. A stringified payload, with or without its outer quotes and with one or several layers, is unescaped and then formatted in one step, so you can read it. Pick the indent in Options.

Why does my JSON show \" and \\n everywhere?

It was stringified before it was stored or logged, once or more, so every quote and line break carries a backslash. Unescape reverses the layers and shows the original document.

Which characters must be escaped in a JSON string?

Only the double quote, the backslash and the control characters U+0000 to U+001F. Everything else, including / and non-ASCII letters or emoji, may be written as is, though \uXXXX is also valid.

Is escaping reversible without loss?

Yes. Unescaping an escaped string returns exactly the characters you started with, emoji and control characters included, as long as the escaped text is unchanged. Escape with the ASCII option on and the \u sequences still decode to the same characters.

Related tools

Learn more