Skip to content
SmaftyTools

String Escape / Unescape

Escape or unescape strings for JavaScript, JSON, HTML, SQL or CSV contexts. Free online string escaping tool, runs in your browser.

About String Escape / Unescape

String Escape / Unescape converts text into a safely embeddable form for five common contexts — JavaScript, JSON, HTML, SQL and CSV — or reverses an already-escaped string back into its plain form. Each context has different rules for which characters need escaping and how, and this tool applies the correct one for whichever you pick.

It's used for safely embedding a string containing quotes or newlines into a JavaScript source file without breaking the syntax, preparing a string as a valid JSON string literal (with its surrounding quotes) to paste into a config or API payload, escaping user-supplied text before inserting it into raw HTML to prevent it from being interpreted as markup, doubling single quotes in a value destined for a hand-written SQL statement, and quoting a CSV field that contains a comma or embedded quote so spreadsheet software parses it as one field rather than splitting it apart.

Each context follows its own real-world convention: JavaScript escaping backslash-escapes quotes, backslashes and whitespace control characters (\n, \r, \t); JSON escaping produces a complete, valid JSON string literal including the surrounding double quotes (matching what JSON.stringify produces); HTML escaping converts the five characters that have special meaning in markup (& < > " ') to their named entities, and unescaping also decodes numeric entities like &#39; or &#x27;; SQL escaping doubles single quotes per the ANSI SQL standard (the classic defense against breaking out of a string literal, though parameterized queries remain the correct defense against SQL injection in real applications); and CSV escaping wraps a value in double quotes and doubles any internal quotes, per RFC 4180.

Unescape mode reverses each of these precisely — including validating that JSON unescape input is actually a valid quoted JSON string literal, since not every string can be safely unescaped as JSON. All conversion happens instantly in your browser as you type or switch context; nothing is uploaded.

How to Use the String Escape / Unescape

  1. Choose a context: JavaScript, JSON, HTML, SQL or CSV.
  2. Choose Escape or Unescape.
  3. Type or paste your text and copy the converted result.

Features

  • Five contexts: JavaScript, JSON, HTML, SQL and CSV
  • Escape and unescape in both directions for every context
  • JSON mode produces a complete, quoted string literal like JSON.stringify
  • HTML unescape handles both named and numeric entities

Examples

Escaping a string for JavaScript

Input

Line1
"quoted"	end

Output

Line1\n\"quoted\"\tend

Escaping a string as a JSON literal

Input

She said "hello"

Output

"She said \"hello\""

Escaping HTML special characters

Input

<b>Tom & Jerry</b>

Output

&lt;b&gt;Tom &amp; Jerry&lt;/b&gt;

Frequently Asked Questions

Why does JSON escape mode add quotes around my text?

A valid JSON string literal includes its surrounding double quotes as part of the value — this matches exactly what JSON.stringify(yourText) produces in JavaScript, so the output is ready to paste directly into a JSON document.

Does SQL escaping here prevent SQL injection?

It performs the standard single-quote-doubling escape, which is the traditional textual defense, but real applications should use parameterized queries / prepared statements as the actual defense against SQL injection — this tool is best used for quick manual editing of SQL snippets, not as a substitute for query parameterization in application code.

What HTML entities does unescape handle?

The five named entities (&amp; &lt; &gt; &quot; &#39;/&apos;), plus &nbsp;, plus numeric entities in both decimal (&#39;) and hexadecimal (&#x27;) form — covering the entities you'll actually encounter when unescaping real HTML content.

Is the string escape tool free?

Yes, the string escape tool is completely free with no usage limits. No signup, no account and no installation required.

Is my data safe?

Yes. All processing happens locally in your browser using JavaScript — nothing you type is uploaded or stored on our servers.