JSON string escape and unescape — quotes, backslashes, newlines, \u codes

Paste raw text to get it back as a safe JSON string value, with quotes, backslashes, tabs and line breaks escaped, or paste an escaped string to read it as plain text again.

Live demo · real result from this tool
Mode

JSON string

She said \"hi\"\nPath: C:\\temp\tdone

Processed on your device — nothing is uploaded.

How to use the JSON string escaper

  1. Paste or type your text into Text.
  2. Choose Mode: Escape turns raw text into JSON string content; Unescape does the reverse.
  3. In Escape mode, tick Wrap in double quotes if you want a complete string value, and Escape non-ASCII as \uXXXX if the target only accepts plain ASCII.
  4. Copy the result. In Unescape mode the output is the plain text, with real line breaks.

What it does and when to use it

Use Escape when you drop text into a JSON document by hand: an error message for a test fixture, a multi-line SQL query in a config file, a Windows path, or a prompt for an API request body. Unescaped, the first double quote or line break ends the string and the file stops parsing.

Use Unescape to read a log or API value that arrives as one long line full of \n and \".

To check that a whole document is valid after your edit, run it through the JSON validator or the JSON formatter. For JavaScript source strings (single quotes, \x escapes, template literals) the JS Unicode escaper is the better fit, and for other targets such as regex or CSV there is a general string escaper.

How it works

Escape mode passes your text to the browser’s own JSON.stringify and removes the outer quotes, so the result matches what any JavaScript program would write. That follows the string rules in section 7 of RFC 8259: quote, backslash and control characters must be escaped, and anything else may be. The ASCII option then replaces every character from U+007F upward with a lowercase \uXXXX code.

Unescape mode reads the text as the inside of a JSON string. Surrounding quotes are optional: without them, the tool adds quotes and escapes any bare double quotes. Real line breaks and tabs count as \n and \t. A strict parser then decodes it and names the first escape it does not accept.

Worked examples

Escape, with the default sample text (a quote, a newline, a backslash and a tab):

Input:   She said "hi"
         Path: C:\temp	done
Output:  She said \"hi\"\nPath: C:\\temp\tdone

Escape with Escape non-ASCII as \uXXXX ticked:

café ☕ 😀   →   caf\u00e9 \u2615 \ud83d\ude00

Unescape of "Line one\nLine two \u2192 done" gives two lines of text, the second reading Line two → done. Unescape of it\'s fails with Invalid escape sequence \', because JSON has no single-quote escape.

Limits and tips

  • In Unescape mode a real tab or line break in the input is kept as it is, as if it were written \t or \n.
  • Escape mode does not touch /. JSON allows \/ but never requires it.
  • It works on one string value at a time, not on a whole document.
  • Everything runs in your browser; the text is not sent anywhere.

Frequently asked questions

Which characters does Escape change?
Only the ones JSON requires. The double quote becomes \", the backslash becomes \\, and control characters (U+0000 to U+001F) become \n, \t, \r, \b, \f or a \u00XX code. Everything else, including the forward slash and accented letters, stays as it is unless you tick the non-ASCII option.
Why does an emoji turn into two \u codes?
A \u escape holds four hex digits, which only covers the first 65,536 code points. Characters above that, such as most emoji, are written as a UTF-16 surrogate pair, so 😀 becomes \ud83d\ude00. Every JSON parser joins the pair back into one character.
Why does Unescape reject \' or \x41?
Those are JavaScript escapes, not JSON escapes. JSON allows only \" \\ \/ \b \f \n \r \t and \uXXXX, so the tool stops and names the escape it could not read. For JavaScript string literals use the JS Unicode escaper instead.
Is the escaped text safe to put inside an HTML script tag?
Not by itself. JSON escaping leaves < and / alone, so a value containing </script> can still end the script block early. Escape those characters for HTML separately if your JSON is printed into a page.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close