String Escape Tool
Escape and unescape strings for various programming languages. Free, fast, and works entirely in your browser with no sign-up required.
Updated
String Escape / Unescape
Escape and unescape strings for JavaScript, JSON, HTML, XML, URL, CSS, RegEx, SQL, CSV, and Markdown — with diff highlighting, explain mode, and batch processing.
Input
Output
All Escape Modes
Related Tools
Frequently Asked Questions
What is the difference between escaping and encoding a string?
Escaping and encoding overlap but are not identical. Escaping inserts a marker character — usually a backslash or an entity — so a parser treats the next character as literal data rather than a command, like turning a quote inside a JavaScript string into \" or a < in HTML into <. Encoding maps characters to an entirely different representation for safe transport, such as percent-encoding a space to %20 in a URL or Base64 turning bytes into ASCII. In practice the term "escape" covers both ideas because the goal is the same: stop a special character from being misread. This tool handles the escape-style transforms developers hit most — JavaScript, JSON, HTML, XML, CSS, RegEx, SQL, CSV, and Markdown — plus URL percent-encoding. Pick the format that matches where the string will live, and it applies the correct rules for you.
How do I escape special characters in a SQL query to prevent injection?
In SQL the character that breaks queries most often is the single quote, because it ends a string literal early; the standard fix is to double it, so O'Brien becomes O''Brien. Backslashes and other metacharacters can matter depending on the database. This tool's SQL mode applies that quote-doubling for you, and its built-in preset even shows the classic Robert'); DROP TABLE Students;-- injection string so you can see what unescaped input would do. Important caveat: manually escaping quotes is a last resort, not real protection. The correct defense against SQL injection is parameterized queries or prepared statements, where the database treats user input as data and never as executable SQL. Use this tool to understand and debug escaping, or to safely embed a literal value, then paste your string into SQL mode to preview the escaped result.
Why does my JSON break when a string contains quotes or newlines?
JSON strings are wrapped in double quotes, so any double quote inside the value ends the string early and the parser throws a syntax error. The same happens with raw line breaks, tabs, and backslashes, because JSON does not allow literal control characters inside a string — they must be written as escape sequences like \n for a newline, \t for a tab, and \" for an embedded quote. When you paste text copied from a document or an API response that still has real newlines in it, the structure collapses. This tool's JSON mode rewrites those characters into valid escape sequences in one step, so the string drops cleanly into a payload or config file. Switch to unescape to reverse it and read the decoded text. Paste your value, choose JSON, and copy the parser-safe result.
Which characters need to be escaped in a regular expression?
Regular expressions reserve a set of metacharacters that carry special meaning, so to match them literally you must escape each one with a backslash. The common ones are the dot (.), asterisk (*), plus (+), question mark (?), caret (^), dollar sign ($), parentheses ( ), square brackets [ ], curly braces { }, the pipe (|), and the backslash itself. For example, to match a literal period in a price you write \. instead of ., because a bare dot matches any character. Forgetting this is a frequent source of patterns that match far too much or fail silently. This tool's RegEx mode scans your text and backslash-escapes every metacharacter automatically, which is ideal when you need to feed a fixed string — like a URL or file path — into a pattern. Paste the value, select RegEx, and copy the safe pattern fragment.
How do I escape commas and quotes inside a CSV field?
CSV treats commas as column separators and newlines as row separators, so any field that actually contains a comma, a line break, or a double quote must be wrapped in double quotes; otherwise a stray comma shifts every column after it. When the field already has a double quote, that inner quote is escaped by doubling it, so she said "hi" becomes "she said ""hi""". This quoting rule comes from the RFC 4180 convention that spreadsheet tools like Excel and Google Sheets follow. Doing it by hand across a column of values is tedious and easy to get wrong. This tool's CSV mode applies the wrapping and quote-doubling for you, and batch mode lets you process many lines at once with the same rule. Paste your fields, choose CSV, and copy output that imports cleanly without breaking the column layout.
Embed This Tool
Add a free, live version of this widget to your own website or blog post — it runs entirely in your visitors' browsers, with a credit link back to The Toolbox.
<iframe src="https://getthetoolbox.com/embed/string-escape" title="String Escape Tool — The Toolbox" width="100%" height="240" style="max-width:480px;border:1px solid #e2e8f0;border-radius:12px" loading="lazy"></iframe>
<p style="font-size:12px;margin:4px 0 0"><a href="https://getthetoolbox.com/utility-tools/string-escape?utm_source=embed&utm_medium=widget" target="_blank" rel="noopener">Free String Escape Tool</a> by The Toolbox</p>Related Tools
Free Secure Password Generator
Generate secure, random passwords with customizable options. Free, fast, and works entirely in your browser with no sign-up required.
Free UUID/GUID Generator
Generate universally unique identifiers (UUIDs/GUIDs). Free, fast, and works entirely in your browser with no sign-up required.
Free QR Code Generator Online
Create QR codes for URLs, text, WiFi, and contacts. Customize colors, size, and error correction. Free, private — runs in your browser, no sign-up.
Free JSON Formatter & Validator
Format, validate, and beautify JSON data with syntax highlighting and error detection. Free, fast, and works entirely in your browser with no sign-up required.
About the String Escape Tool
The String Escape Tool escapes and unescapes text for ten different programming contexts, so a string that would otherwise break your code, your query, or your markup becomes safe to drop in exactly where you need it. Paste a value, pick a format, and choose a direction — escape to make the string literal-safe, or unescape to turn an encoded value back into the characters it represents. It is built for developers, but anyone wrangling config files, spreadsheets, or API payloads will find it useful.
Everything runs locally in your browser. The text you paste — which might be a production SQL query, an auth token, or a snippet of customer data — is never sent to a server. There is no sign-up, no length cap, and nothing to install.
Ten escape formats, both directions
Escaping means replacing characters that have special meaning in a given syntax with a safe equivalent, so the parser treats them as literal data instead of instructions. The tool supports the formats where this matters most:
- JavaScript and JSON — escape quotes, backslashes, and control characters (
\n,\t,\r) so a string is valid inside a literal or a JSON value. - HTML and XML — convert
<,>,&, and quotes into entities like<and&so content renders as text rather than markup. - URL — percent-encode characters such as spaces and
&so a value survives inside a query string. - CSS, RegEx, SQL, CSV, and Markdown — escape the metacharacters that each of these treats specially, from regex's
.*()to CSV's embedded commas and quotes.
Every format works in reverse too. A one-click Swap sends the output back into the input box, so you can round-trip a value or undo an encoding without retyping anything.
Why escaping prevents real bugs and exploits
Unescaped input is one of the oldest sources of broken software and security holes. An apostrophe in a name like O'Brien can break a naïvely built SQL statement; that same gap, left open, is what SQL injection exploits. A <script> tag pasted into a page that doesn't escape HTML is the basis of cross-site scripting (XSS). A stray comma in a CSV field shifts every column after it. Escaping the right characters for the right context is the fix in each case.
The built-in presets demonstrate exactly these scenarios — a classic XSS payload for HTML, the Robert'); DROP TABLE Students;-- injection string for SQL, a URL with spaces, and JSON containing tabs and newlines — so you can see the safe output before trusting it in your own work. Treat the tool as a learning and debugging aid; it is not a substitute for parameterized queries or a framework's own escaping at runtime.
Explain mode, diff view, and batch processing
Beyond the standard single-string view, the tool offers two extra modes. Explain mode walks through the output character by character, naming each special character and the reason it was escaped — for example, that & is reserved in HTML markup or that a backslash is the escape character itself. The diff highlighting shows precisely what changed between input and output, and a running character-difference count tells you how much the string grew or shrank.
Batch mode processes many lines at once, applying the same format and direction to each, which is handy for a column of values or a list of test strings. A history panel keeps your recent conversions within reach, and you can copy any result to the clipboard or download it as a .txt file.
Pick a format above, paste your text, and switch between escape and unescape to see the result update right away.