Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste the raw text, not an already escaped literal.
  2. Copy the quoted result, including the surrounding quotes.
  3. Paste that result into JSON unescape if you need the original back.
  4. Use the minifier instead when the paste is a document you want compacted.

What is JSON escape?

A JSON string is not the characters you see. A quote has to be escaped, a newline has to become \n, and a backslash has to be doubled. JSON escape takes the text you paste and returns one JSON string literal, including the surrounding quotes.

Read more

The two characters a quote and a newline, written between a and b as a" then a line break then b, escape to the literal "a\"\nb". That is a quote, the letter a, a backslash, a quote, a backslash, n, the letter b, and a closing quote. JSON unescape of that literal returns the original two lines. The round trip is the check that the escaping is reversible.

This is not minifying a document. The minifier parses JSON and writes it compactly. Escape treats the whole paste as raw text, even if the paste happens to look like JSON. The sample object {"color":"red","count":2} escaped as text becomes a quoted string whose contents are the escaped braces and quotes.

Use cases

  • A developer embedding a paragraph inside a JSON config value.
  • A student checking that a newline survived as \n rather than as a real line break.
  • A support engineer preparing a string for a payload without breaking the surrounding JSON.
  • Someone reversing the operation with unescape to prove nothing was lost.
  • An author who pasted a document and needs it as one string value, not as an object.

A quote and a newline

The characters a, a double quote, a newline, and b.

The JSON string literal "a\"\nb". Unescape returns the original two lines.

Why use Oddsock

The escape is JSON.stringify of the text, so the literal is legal to drop into a string field without hand-counting backslashes.

Related tools

Using this tool

No. Every character is data. A brace is a brace inside the string, not the start of an object.