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 ' or '; 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
- Choose a context: JavaScript, JSON, HTML, SQL or CSV.
- Choose Escape or Unescape.
- 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
<b>Tom & Jerry</b>
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 (& < > " '/'), plus , plus numeric entities in both decimal (') and hexadecimal (') 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.
Related Tools
HTML Entity Encoder
Encode special characters as HTML entities or decode entities back to text. Handles named, decimal and hex entities.
JSON Formatter
Format, validate and beautify JSON online. Free JSON formatter with indentation options and key sorting — runs entirely in your browser.
URL Encode/Decode
Encode or decode URLs and query strings online. Free URL encoder/decoder for percent-encoding special characters.
Base64 Encode/Decode
Encode text to Base64 or decode Base64 to text instantly. Free online Base64 converter — no upload, everything stays in your browser.
SQL Formatter
Format SQL queries with uppercase keywords and clean clause indentation. Free online SQL beautifier — runs in your browser.
JavaScript Beautifier / Minifier
Beautify minified JavaScript into readable code, or minify it to shrink file size. Free online JS formatter — runs entirely in your browser.
HTML Formatter / Minifier
Beautify HTML into readable, indented markup or minify it to shrink file size. Free online HTML formatter, no upload required.
Binary to Text Converter
Convert text to binary code or decode binary back to readable text, byte by byte. Free online binary to text converter and text to binary translator.