ToolsTray

Star a tool to keep it here.

String Escaper

JSON escape and unescape, plus JavaScript literals, \uXXXX Unicode and backslash sequences. Four modes, both directions.

JSON string

The escaped text appears here.

Every sequence it writes is marked.

Style, and the first line under each

Direction

What changed

—escaped

How to use

  1. Choose the Direction: Escape for raw text going into a string, Unescape for an escaped string coming back out.
  2. Choose the style from the four cards. Each card already shows your first line in its style and its length, so the right one is usually the one that reads the way you need.
  3. Type or paste into the first well. The second well and the report follow as you type; Copy output takes the result, and the swap between the wells sends it back as the input with the direction turned round.

About this tool

Choose Escape, pick a style, type or paste: the escaped text follows in the second well as you go, every sequence it wrote marked. JSON escape is what most people arrive for: you hand it a value with quotes and line breaks in it, and you get back something that will sit between the quotes of a JSON string without splitting the document open.

The four styles are not interchangeable and the gaps between them are small enough to catch you out, so the four cards under the wells show your first line in every style at once, each with its length. JSON leaves a single quote alone; JavaScript escapes it to \'. Non-ASCII is the bigger split, because JSON hands é and 🚀 straight through while JavaScript rewrites everything outside printable ASCII as \uXXXX. Unicode \uXXXX ignores anything below code point 128, so your newlines stay real newlines. Escape characters is the narrow one and knows exactly four things: backslash, newline, carriage return, tab.

Unescape runs the same four styles backwards and says what it could not read. JSON is checked against the rules for a JSON string by the page's own scan, so every raw quote, raw control character or undefined escape is lit at its character and the last good output stays on screen, dimmed, with Escape instead one press away. JavaScript reads \q as q, the way JavaScript itself does, and says so; a \u short of its four hex digits stays standing rather than turning into a stray character.

Emoji and other astral characters are handled a UTF-16 code unit at a time, so 🚀 leaves JavaScript or Unicode mode as the surrogate pair \ud83d\ude80, and the page names the pair. Run it back the other way and the emoji reassembles; a half left on its own is lit, because it is half a character.

What it will not catch

  • Escaping covers the value, never the syntax wrapped around it. You still write the quotes yourself, and making the surrounding JSON valid is still your job.
  • JSON escape leaves non-ASCII where it found it, so é and 🚀 come through as themselves. That is valid JSON. If you need the result to be pure ASCII, JavaScript mode gets you there, but only when the text has no single quotes in it, because JavaScript escapes those to \' and JSON has no such escape.
  • HTML entities and URL percent-encoding are separate tools on this site. CSV field quoting and SQL string quoting have no tool here, and none of these four styles will stand in for them.

Frequently asked questions

Which style do I want for pasting a value into JSON?

JSON string. It runs the same JSON.stringify your language does and then strips the outer pair of quotes, so what comes out is the inside of a JSON string value: quotes become \", backslashes double up, and line breaks and tabs turn into \n, \r and \t. Put it between a pair of quotes and the document parses.

How do I turn \u00e9 back into é?

Choose Unescape and the Unicode \uXXXX card. It looks for a backslash followed by four hex digits, swaps in the character, and touches nothing else, so a file mixing readable text with the odd escape comes out readable with the rest undisturbed. JavaScript does the same job and handles \xNN and \u{...} on top.

Can I paste a whole JSON file in and unescape it?

A whole document is not the inside of one string: it carries raw quotes and real line breaks, and JSON unescape lights every one of them. Pull out the string you care about, or use JSON Formatter for the document.

Unescape did nothing to my text. What did I get wrong?

Check the style first. Unicode \uXXXX only reacts to a backslash plus four hex digits, and Escape characters only knows \n, \r, \t and a doubled backslash. The cards show your first line under all four, so the one that changes it is the one that reads your text.

Missing something in String Escape & Unescape (JSON, JavaScript, Unicode)? Suggest a feature →

Tell someone who needs this.