ToolNimba Browse

🔣 JSON Escape and Unescape

By ToolNimba Web Dev Team · Updated 2026-06-19

Type above to see the escaped output.

This tool escapes and unescapes JSON strings, both ways, in your browser. Paste raw text and it produces a safe JSON string value with quotes, backslashes, newlines and tabs escaped, ready to drop into a JSON document or a code literal. Switch to unescape mode to turn an escaped JSON string back into the plain, human-readable text it represents. Nothing is uploaded: everything runs locally with the browser built-in JSON parser.

What is the JSON Escape Unescape?

JSON has a small but strict set of rules for what may appear inside a string. The string is wrapped in double quotes, and certain characters are not allowed to sit raw between those quotes: the double quote itself, the backslash, and the ASCII control characters (anything below code point 0x20, such as newline, carriage return and tab). To include them you escape them with a backslash, so a double quote becomes \", a backslash becomes \\, a newline becomes \n, a tab becomes \t, and an arbitrary control character becomes a \u escape like \u0000. Escaping is simply the act of rewriting raw text so it obeys these rules.

The most reliable way to escape text is the language built-in JSON serializer rather than a hand-written replace. This tool uses the browser JSON.stringify function, which turns your text into a fully quoted, fully escaped JSON string, then trims the outer quotes so you get just the escaped body (you can keep the quotes with one checkbox). Unescaping is the exact inverse: it uses JSON.parse to decode every escape sequence back to the character it stands for. Using the same engine that browsers, Node and most servers use means the result matches what real JSON parsers will accept, with no edge cases missed.

Escaping and unescaping are reversible: escape a piece of text, then unescape the result, and you are back to the original. This matters when you embed data inside data, for example putting a JSON payload inside another JSON field, or pasting a multi-line message into a configuration file, a log line, or a string literal in source code. Get the escaping wrong and the parser stops at the first stray quote, so a correct, automatic escape saves a lot of debugging.

When to use it

  • Turning a block of text, with quotes and line breaks, into a single safe JSON string value you can paste into a request body or config file.
  • Embedding a JSON snippet inside another JSON field, where the inner braces and quotes must all be escaped.
  • Building a string literal for source code by escaping text the same way the language would.
  • Reading an escaped string out of a log file or API response by unescaping it back into plain, multi-line text.

How to use the JSON Escape Unescape

  1. Pick Escape to convert raw text into a JSON string, or Unescape to convert a JSON string back to raw text.
  2. Type or paste your text into the input box.
  3. Read the converted result in the output box below, it updates as you type.
  4. Optionally tick "Wrap output in double quotes" to include the surrounding quotes around the escaped value.
  5. Press Copy to put the result on your clipboard, or Swap to send the output back into the input.

Formula & method

Escape: result = JSON.stringify(text), then drop the outer quotes unless you keep them. Each special character maps as " to \", \ to \\, newline to \n, carriage return to \r, tab to \t, and control chars to \uXXXX. Unescape: result = JSON.parse("text"), which reverses every escape sequence.

Worked examples

Escape the raw text: She said "hi" then pressed Tab (a real tab) and a newline.

  1. Start with the raw characters: She said "hi" [tab] [newline]
  2. JSON.stringify wraps it in quotes and escapes each special character.
  3. The double quotes around hi become \" and \"
  4. The tab becomes \t and the newline becomes \n
  5. Trim the outer quotes to get just the escaped body.

Result: She said \"hi\" then pressed Tab\t and a newline.\n

Unescape the JSON string value: C:\\Users\\me\\file.txt

  1. Input is the escaped text C:\\Users\\me\\file.txt
  2. Wrap it in quotes so JSON.parse sees a complete string token.
  3. JSON.parse reads each \\ as a single backslash.
  4. No other escape sequences are present.

Result: C:\Users\me\file.txt

Characters that must be escaped inside a JSON string

CharacterEscaped formMeaning
"\"Double quote
\\\Backslash
newline\nLine feed (U+000A)
carriage return\rCarriage return (U+000D)
tab\tHorizontal tab (U+0009)
other control char\uXXXXAny character below U+0020

Optional escapes JSON allows but does not require

CharacterEscaped formNote
/\/A forward slash may be escaped but never has to be.
backspace\bControl character U+0008.
form feed\fControl character U+000C.

Common mistakes to avoid

  • Escaping by hand and missing a case. Replacing only quotes and forgetting backslashes, newlines or control characters produces a string that breaks at parse time. Using the JSON serializer, as this tool does, covers every required case automatically.
  • Double-escaping already-escaped text. Running escape twice turns \n into \\n, so the parser later returns a literal backslash-n instead of a newline. Escape exactly once, and use Unescape to reverse it.
  • Confusing the escaped body with the full string. The escaped body has no surrounding quotes, while a complete JSON string value does. Use the "Wrap output in double quotes" option when you need the full quoted value, and leave it off when you are inserting into an existing pair of quotes.
  • Pasting quotes into unescape mode incorrectly. Unescape accepts text with or without the outer quotes, but a stray unescaped quote in the middle is invalid JSON and will be rejected. Make sure inner quotes are written as \" before unescaping.

Glossary

Escape
Rewriting a character as a backslash sequence so it is allowed inside a JSON string, for example a newline written as \n.
Unescape
The reverse of escaping: decoding backslash sequences back into the raw characters they represent.
JSON string
A run of characters wrapped in double quotes, with special characters escaped, as defined by the JSON standard.
Control character
A character with a code point below U+0020 (such as tab or newline) that may not appear raw inside a JSON string.
Unicode escape
The form \uXXXX, four hex digits that encode a character by its code point, used for control characters and any character.

Frequently asked questions

What does it mean to escape a JSON string?

Escaping rewrites text so it is valid inside a JSON string. Characters that are not allowed raw, such as double quotes, backslashes, newlines and tabs, are replaced with backslash sequences like \", \\, \n and \t. The result can be pasted between quotes in a JSON document without breaking the parser.

How do I unescape a JSON string?

Switch to Unescape mode and paste the escaped string. The tool decodes every backslash sequence back to the character it stands for, so \n becomes a real newline and \" becomes a plain double quote. You can paste the value with or without its surrounding double quotes.

Does this tool send my text anywhere?

No. All escaping and unescaping happens in your browser using the built-in JSON.stringify and JSON.parse functions. Your text is never uploaded to a server, so it is safe to use with private or sensitive data.

Should the output include the surrounding double quotes?

It depends on where you are pasting. If you are inserting the value into an existing pair of quotes, leave the quotes off (the default). If you need a complete JSON string value on its own, tick "Wrap output in double quotes" to include them.

Why does my input get rejected in unescape mode?

Unescape uses a real JSON parser, so the text must be a valid JSON string. A common cause is an unescaped double quote or a lone backslash in the middle of the text. Escape those first (a quote as \", a backslash as \\) and try again, or check you are not in the wrong mode.

Is JSON escaping the same as URL or HTML escaping?

No. Each format has its own rules. URL encoding uses percent escapes like %20, and HTML uses entities such as the ampersand. JSON escaping uses backslash sequences such as \n and \". Use the encoder that matches the format you are targeting.