JSON looks simple until a quotation mark appears inside a string. A JSON string is wrapped in double quotes, so a quote inside the text would end the string early unless it is marked as part of the content rather than as a delimiter. The same problem applies to backslashes, line breaks, tabs, and control characters: each of them has a meaning in JSON syntax, or no allowed raw form at all, so each must be represented by an escape sequence, a short code that stands for the character without confusing the parser.

Escaping is that representation. To escape a string means to replace each special character with its escape sequence, and to wrap the result in quotes, producing a valid JSON string literal. To unescape means to reverse the process: take a JSON string literal, remove the wrapping quotes, and replace each escape sequence with the character it stands for, recovering the original text. The two operations are inverses, and a round trip, escape then unescape, should return exactly the text you started with. When it does not, something in the process was wrong, and the difference tells you where.

The JSON Escape and Unescape tool performs both directions on text you paste in, in your browser. It has two actions rather than one, because escaping and unescaping are genuinely different operations, and a single button would have to guess which one you meant. You choose Escape to turn plain text into a JSON string literal, or Unescape to turn a JSON string literal back into plain text.

How escaping works

The rules are small enough to list completely. A double quote becomes \" , a backslash becomes \, a line break becomes \n, a carriage return becomes \r, and a tab becomes \t. Other control characters, which cannot appear raw in a JSON string at all, become \u followed by four hexadecimal digits giving the character's code. Everything else, including ordinary letters, digits, spaces, and most punctuation, stays as it is. The escaped text is then wrapped in double quotes, producing the string literal.

Unescaping applies the same table in reverse. The tool checks that the input is wrapped in quotes, removes them, and then replaces each escape sequence with the character it represents: \" becomes a quote, \ becomes a backslash, \n becomes a line break, and so on. If the input is not wrapped in quotes, the tool refuses it, because bare text without quotes is not a JSON string literal, and unescaping it would be guessing. That refusal is a feature: it catches the common error of pasting plain text and clicking the wrong button.

Order matters inside the escaping process, and it is the reason hand-escaping is error-prone. Backslashes must be escaped before any other replacement introduces new backslashes, or the newly introduced backslashes will themselves be escaped, doubling them incorrectly. A tool applies the replacements in the correct order every time, which is the main reason to use one rather than doing it by hand in a text editor's find-and-replace.

A worked example

Take the plain sentence: He said "hello". It contains a pair of double quotes that would break a JSON string if left raw. Escape it, and the result is "He said \"hello\".", a JSON string literal: the outer quotes delimit the string, and each inner quote is preceded by a backslash marking it as content. Paste that literal back into the tool and unescape it, and you recover exactly He said "hello"., with the quotes restored and the wrapping quotes removed. The round trip is exact, which is the test that matters.

Now try a multi-line example. Plain text with a line break between two lines, such as a short address written over two lines, escapes to a single-line literal with \n standing for the break. That single line can sit safely inside a JSON object, in a configuration file, or in a line of code, where a raw line break would break the structure. Unescape it, and the line break returns, restoring the two-line form. That is why escaping exists: it lets text containing awkward characters travel through formats that would otherwise choke on them.

A third example shows the backslash trap. The plain text C:\new\file contains backslashes, and \n inside it looks like a line break to a naive reader. Escaped correctly, each backslash doubles, so the literal contains \ where the plain text had \, and unescaping restores the single backslashes. If you escape by hand and forget the backslashes, the \n in the path will be read as a line break on unescaping, and the path will come back corrupted. The tool's ordered replacement prevents exactly that error.

Common mistakes

The first mistake is double-escaping: escaping text that is already escaped. Each pass adds another layer of backslashes, so "hello" becomes \"hello\" and then \\"hello\\", and the text drifts further from the original with every pass. If your output has more backslashes than you expected, you probably escaped twice. Unescape once to check, and work from the plain text.

The second mistake is the reverse: unescaping plain text that was never escaped. The tool refuses bare text without quotes for unescaping, which catches this, but other tools may silently return the text unchanged or mangle it. Always know which form you hold before choosing an action: plain text gets escaped, a quoted literal gets unescaped. The third mistake is escaping by hand with find-and-replace in the wrong order, particularly forgetting backslashes first, which corrupts paths and Windows-style text as shown above.

The fourth mistake is assuming escaped text is safe for every context. JSON escaping makes text safe inside a JSON string, but it does not make it safe inside HTML, a URL, or a database query, each of which has its own escaping rules. A string that is valid JSON can still break HTML if it contains markup, and a string that is safe in JSON can still be dangerous if inserted into a page without HTML escaping. Escape for the format you are actually writing into, not for formats in general.

Honest limitations

This tool converts plain text to a JSON string literal and back, in your browser. It does not validate a full JSON document, parse objects or arrays, or check that a larger JSON file is well-formed; it works on one string at a time. It refuses bare text without quotes for unescaping, because that input is not a JSON string literal, and it does not guess at malformed escape sequences, which should be fixed at the source rather than silently repaired. It also does not escape for HTML, URLs, or any other format: its output is correct for JSON strings and should not be reused as if it were correct elsewhere.

Closing

Escape when text enters JSON, unescape when it leaves, and check the round trip when in doubt. That discipline prevents a whole class of small, maddening bugs. For related work, validate a full document with the JSON Schema Validator tool, encode text for URLs with the URL Encoder & Decoder tool, and read our guide How to Format and Validate JSON to keep the surrounding JSON tidy.