Escape / Unescape

Escape / Unescape

Encode and decode strings for HTML, JSON, SQL, and XML contexts. All computation runs in your browser.

Mode
Input
Output

About the Escape / Unescape Tool

Every language that embeds text has characters with special meaning: < starts a tag in HTML, " ends a string in JSON, and ' ends a literal in SQL. To include those characters as ordinary text, they must be escaped. Getting this wrong breaks documents and, in the worst cases, causes security bugs such as cross-site scripting (XSS) and SQL injection.

This tool escapes and unescapes text for four contexts: HTML entities, JSON strings, SQL string literals and XML entities. Choose a mode, paste your text, and convert in either direction. Use Swap to move the output back into the input.

Common uses

  • Showing code samples containing < and > on a web page or in a blog post.
  • Embedding multi-line text, quotes or file paths inside a JSON string.
  • Writing a quick SQL script with names like O'Brien.
  • Reading escaped strings from logs, API responses or XML config files.

How to use it

  1. Choose the Mode: HTML Entities, JSON String, SQL Literal or XML Entities.
  2. Paste your text into Input (or click Try Me).
  3. Press Escape or Unescape, then copy the output.

Example

The same text escaped for different contexts:

Input
She said "5 < 6" & it's true
Output
HTML: She said &quot;5 &lt; 6&quot; &amp; it&#39;s true
JSON: She said \"5 < 6\" & it's true
SQL:  She said "5 < 6" & it''s true

Tips and common pitfalls

  • Escaping is context-specific. Text that is safe in HTML is not necessarily safe in a JavaScript string, a URL or a CSS value.
  • For SQL, escaping quotes is a last resort for one-off scripts. Application code should always use parameterised queries.
  • In web frameworks, prefer automatic output encoding (Razor, React, Angular and most template engines do this by default) over escaping by hand.
  • For URLs, use the URL Encoder / Decoder — percent-encoding is a different scheme.

Frequently asked questions

What is the difference between HTML and XML escaping?

Both escape &, <, > and quotes. HTML also defines hundreds of named entities such as &nbsp; and &copy;; XML only predefines five (&amp; &lt; &gt; &quot; &apos;).

How are single quotes escaped in SQL?

Standard SQL doubles them: 'O''Brien'. Backslash escaping (\') only works in some databases, such as MySQL in its default mode.

Which characters must be escaped in JSON?

Double quotes, backslashes and control characters (such as newline and tab). JSON allows any other Unicode character to appear as-is.

Is my text processed on a server?

No. All escaping and unescaping happens in your browser.

Related