Toolvito

Works on this device

Text Escape & Unescape Tool

Make text safe to put inside HTML, JSON, a program string, a CSV field or an SQL string, or turn escaped text back into plain text. The result shows as you type. Your text is converted in your browser and is not sent to a server.

Your text

Every character counts, also spaces and line breaks.

Your text is converted in this browser. It is not sent to a server.

The result will show here

Type or paste some text, or choose Try an example.

How to use the escape tool

  1. Choose the format and the direction in the menu, such as HTML: unescape (decode entities) or JSON string: escape.
  2. Type or paste your text. The result shows as you type.
  3. Set the options of that format if you need them, such as the kind of quotation marks.
  4. Choose Copy output or Download output to keep the result.

What escaping is

Many formats give some characters a job. In HTML, < starts a tag. In JSON, " ends a string. In CSV, a comma ends a field. To use such a character as plain text you write it in another way, and that is called escaping. Unescaping turns it back.

Each format has its own rules. Text that is escaped for one format is not safe for another.

The rules of each format

What each format escapes
Format What is changed Example
HTML & < > " ' become character references <b> becomes &lt;b&gt;
XML the same five characters, with &apos; for the apostrophe a & b becomes a &amp; b
JSON string ", the backslash and control characters a line break becomes \n
JavaScript string the backslash, the chosen quotation mark and control characters it's becomes it\'s
CSV field a field with a comma, a quotation mark or a line break is put in quotation marks; " is written twice say "hi" becomes "say ""hi"""
SQL string each single quotation mark is written twice O'Brien becomes 'O''Brien'
Regular expression a backslash before \ ^ $ . * + ? ( ) [ ] { } | 1+1 becomes 1\+1
Shell, single quotes the text is put in single quotes; a single quote is written '\'' it's becomes 'it'\''s'
C string the backslash, " and control characters; others as octal numbers a tab becomes \t
Unicode escapes characters outside ASCII become \u and four hexadecimal digits é becomes \u00E9
Quoted-printable bytes that are not printable ASCII, and =, become = and two hexadecimal digits café becomes caf=C3=A9

Worked example

The text Tom & Jerry's "C:\temp" <b>5*(a+b)?</b> café 😀 escaped for HTML is Tom &amp; Jerry&#39;s &quot;C:\temp&quot; &lt;b&gt;5*(a+b)?&lt;/b&gt; café 😀.

As a JSON string it is Tom & Jerry's \"C:\\temp\" <b>5*(a+b)?</b> café 😀: only the quotation marks and the backslash change.

As an SQL string it is 'Tom & Jerry''s "C:\temp" <b>5*(a+b)?</b> café 😀': the apostrophe is written twice.

The HTML text caf&eacute; &#128512; &euro;5 unescapes to café 😀 €5.

Strict checks

  • Unescaping is strict. A wrong escape, such as \q in JSON or a quotation mark that is not closed, is reported with the number of its character. Nothing is guessed.
  • A \u escape for half of a surrogate pair, with no other half, is an error. The page never makes half a character.
  • HTML names are known for the 252 names of HTML 4 and &apos;. Newer names, such as &NotEqual;, are reported as unknown. Numbers such as &#8800; always work.
  • In HTML, a name with no semicolon, such as &eacute at the end of a word, is left as text. A browser may still read some of these.

Limits you should know

  • Escaping is not a full defence against attacks. For SQL, use a parameterised query (a prepared statement) and do not join text into a query. For HTML, use the escaping of your template system, and note that text inside a script, a style or a URL needs other rules.
  • The SQL rule is standard SQL. Some databases also read a backslash as an escape; this page does not add backslashes.
  • The shell rule is for POSIX shells such as sh, bash and zsh. For Windows, see the Windows Command Line Escaper and the Powershell String Escaper.
  • The page reads text. It never runs it: JavaScript, shell and SQL text is not executed, and HTML is not shown as a page.
  • URL encoding and Base64 have their own tools: the URL Encoder & Decoder and the Base64 Encoder & Decoder.
  • The text can have up to 200,000 characters.

Related tools