Skip to content
🔐

Text Escape and Unescape

Escape or unescape text for JSON, SQL, shell, URL, HTML, and XML.

Runs in your browser

Updated

Result

Input length

0

Output length

0

Characters changed

0

Characters handled

MeaningEscapeIn the output
Escaping is for building a correct value, not for safety on its own. Never build SQL by escaping quotes alone, use a parameterised query. Treat any HTML output as a place you can still inject markup unless you sanitise it deliberately.

What each context does

The page holds a context dropdown and an Escape or Unescape direction toggle. JSON mode feeds the text through the browser's own stringifier and trims the wrapping quotes. SQL doubles single quotes. Shell replaces a single quote with the quote-close, escaped-quote, quote-reopen sequence. URL mode runs encodeURIComponent. HTML replaces five characters (ampersand, both angle brackets, double and single quote) with their named or numeric entities; XML does the first three only. Regex prefixes every metacharacter in the set backslash, caret, dollar, dot, pipe, asterisk, plus, question mark, parentheses, square brackets and braces.

A worked example

The Sample button loads a 27-character string containing quotes, a real newline and a Windows path. In JSON mode the output is 31 characters: each quote becomes a backslash-quote pair, the newline becomes a literal backslash-n, and the single backslash before path doubles. The three counters then read 27 in, 31 out, and 22 for characters changed.

Counters and the reference table

The changed figure counts positions that differ between input and output, then adds the difference in length, so it is a rough measure of how invasive the escaping was rather than an exact character tally. The table underneath lists, per context, which characters are touched and what they turn into; it re-renders whenever you switch contexts. A checkbox trims whitespace from the finished output.

Where it stops

  • URL mode escapes a component; it does not assemble a whole query string, and unescaping converts plus signs to spaces on the way in.
  • SQL doubling only makes a value writable inside single quotes; it is not injection protection, which needs parameterised statements.
  • HTML unescaping is a single pass, so text encoded twice comes back still partly encoded.
  • Unescaping malformed JSON is caught and reported as an error rather than guessed at.

Questions people ask

Why did my quotes vanish when unescaping SQL?

The unescape step collapses doubled quotes back to singles; give it the escaped text, not the original.

Which context covers apostrophes in HTML?

HTML mode, which maps them to the numeric 39 entity; XML mode deliberately leaves quotes alone because only three characters are illegal there.

Related utilities: HTML entity converter for named entities and URL encoder decoder for whole addresses.