Escape and unescape strings online for JSON, HTML, JavaScript, URL, CSV and SQL. This free tool handles backslash escaping, escape sequences for newline, tab and quotes, HTML entities, URL percent-encoding, and SQL injection prevention. Paste any string to instantly see the escaped or unescaped result. Supports Unicode \uXXXX notation, special characters, and all common escape formats. All processing happens client-side in your browser — nothing is uploaded to a server.
| Sequence | Character | Description |
|---|---|---|
| \\ | \ | Backslash |
| \" | " | Double quote |
| \' | ' | Single quote |
| \n | ↵ | Newline (line feed) |
| \r | Carriage return | |
| \t | → | Horizontal tab |
| \b | Backspace | |
| \f | Form feed | |
| \0 | Null character | |
| \uXXXX | Unicode code point (hex) |
Every string-related security incident I have read in the past decade — Equifax, MOVEit, Log4Shell, every weekend's fresh round of XSS reports — traces back to a string that crossed a context boundary without being re-escaped for the new context. Escaping is not boilerplate; it is the rule that keeps user data inside its data envelope and prevents it from being interpreted as code. This guide covers each escaping context the tool supports — what the escape sequences are, what the parser is actually defending against, and the language-level functions you should reach for instead of writing your own.
The single biggest concept to internalise is context-specific escaping. A string flowing from a database into an HTML page should be HTML-escaped at the moment it is written into HTML. The same string flowing into a JavaScript string literal needs JS-string escaping. The same string going into a URL parameter needs percent-encoding. None of these escapings substitute for each other:
| Where the string lands | Escape with | What it prevents |
|---|---|---|
HTML element body (<p>…</p>) | HTML entity escape & < > | HTML/XSS injection |
| HTML attribute value | HTML entity escape + always quote attribute | Attribute breakout, event handlers |
| JavaScript string literal | JS escape (\\ \" \n \uXXXX) | String breakout, code injection |
| URL query parameter | percent-encoding (encodeURIComponent) | Param injection, broken parsers |
| JSON value | JSON escape (JSON.stringify) | JSON parse errors, injection |
| CSV cell | Wrap in "…", double internal "" | Cell breakout, CSV injection |
| SQL value | Don't escape — use a parameterised query | SQL injection |
| Shell command | Don't escape — use exec with arg array | Command injection |
The two "don't escape" rows in that table are deliberate — they are the two places where ad-hoc escaping is the wrong tool. We will come back to them.
RFC 8259 (the current JSON spec) requires escaping just six characters inside string values: ", \, and the U+0000–U+001F control range. Everything else is allowed verbatim, including non-ASCII. Most JSON encoders also escape / defensively (so the string </script> doesn't break out of an inline JSON-in-HTML block), and many escape all non-ASCII to \uXXXX for transport safety:
\" — double quote\\ — backslash\/ — forward slash (optional, but recommended for </script> safety)\b \f \n \r \t — control whitespace\uXXXX — any other control character or non-ASCIIThe simple rule in JavaScript: if you can use JSON.stringify(value), do that. It is correct, fast, and tested by every browser vendor. Hand-rolling JSON escaping is how you get parse errors with surrogate pairs and U+2028 (line separator, which used to break JSONP).
OWASP's HTML escaping recommendation is to encode five characters in element bodies:
| Char | Entity | Why |
|---|---|---|
& | & | Must come first or it'll re-escape your other entities |
< | < | Prevents tag injection |
> | > | Defensive; some legacy parsers care |
" | " | Prevents attribute-value breakout |
' | ' or ' | Same — ' isn't valid in HTML4 |
This baseline covers element-body and double-quoted-attribute contexts. It does not cover JavaScript-event attributes (onclick), style attributes, or href/src URLs — those need additional context-specific encoding. The rule of thumb: never put untrusted data inside <script>, <style>, or unquoted attributes, ever.
This trips up everyone at least once. JavaScript ships two URL-encoding functions and they do different things:
encodeURI(url) — encodes a full URL but leaves : / ? & = # alone because they are URL syntax characters. Use this on a complete URL you want to make safe for transmission, never on user data.encodeURIComponent(value) — encodes everything except A-Z a-z 0-9 - _ . ! ~ * ' ( ). Use this on every individual query parameter value or path segment.If you ever find yourself reaching for escape() — stop. escape() is deprecated, produces non-standard output for non-ASCII, and is the wrong answer for everything in 2026.
CSV escaping is delightfully short:
,, ", \r, or \n, wrap the entire field in double quotes." (so a single quote becomes "").That is it. There is no standard backslash escaping in CSV; \n as two characters is treated literally. The other major risk — CSV injection — is when a field starts with =, +, -, or @ and Excel evaluates it as a formula on import. The OWASP fix: prefix any such cell with a single quote (') before saving. The picker handles RFC 4180 escaping; CSV-injection prefixing is a downstream sanitization step.
SQL "escaping" is the most dangerous category in this list. The historical pattern was to double-up single quotes (O'Brien → O''Brien) and string-concatenate the result into a query. Do not do this. Quoting alone does not defend against:
% and _ requires a separate ESCAPE clause.0xBF 0x27 bypass on misconfigured MySQL connections.The correct answer is parameterised queries / prepared statements, where the database driver sends the SQL template and the values separately and the database engine never confuses them. Every modern driver supports this:
await client.query('SELECT * FROM users WHERE email = $1', [userEmail]);cur.execute('SELECT * FROM users WHERE email = %s', (user_email,))PreparedStatement ps = conn.prepareStatement(
"SELECT * FROM users WHERE email = ?");
ps.setString(1, userEmail);The SQL escape mode in this tool exists for emergency cases (one-off scripts, escaping a literal for a SQL editor pasted by hand). It should never be the layer that protects production code from injection.
JavaScript string literals support a long list of escapes, and a few have non-obvious behavior:
\xNN — two-digit hex, U+0000 to U+00FF.\uNNNN — four-digit hex, U+0000 to U+FFFF (a single UTF-16 code unit, which means surrogates land here).\u{NNNNNN} — variable-length, full Unicode 0x0 to 0x10FFFF (ES2015+). Use this for emoji and astral characters; it produces a correct surrogate pair.\0 — null, but only when not followed by a digit. \01 is an octal escape and a syntax error in strict mode.\v — vertical tab (U+000B), almost never used.JavaScript also has two characters that can break inline JSON-in-script blocks: U+2028 (line separator) and U+2029 (paragraph separator). They are valid in JSON but were illegal in JS string literals until 2019. Older code that writes <script>var data = ${JSON.stringify(x)};</script> needs to escape these to
/
for safety.
&amp; appear in your UI. Encode once, at the boundary.{{x}}, JSX {x}, Jinja2 autoescape on). Mistakes are caught at the language level.encodeURIComponent on something that's already encoded you get %2520 instead of %20.innerHTML with sanitised input. Even sanitised HTML can carry mutation-XSS payloads. Prefer textContent for plain text; use setAttribute for attributes; use a vetted HTML sanitiser (DOMPurify) when you really need to render rich HTML.encodeURIComponent, JSON.stringify, DOMPurify.sanitize) instead.\" to avoid prematurely ending the string. Without proper escaping, special characters like quotes, backslashes, newlines, and tabs would break parsers, cause syntax errors, or create security vulnerabilities such as SQL injection and XSS attacks.
\"), backslash (\\), newline (\n), tab (\t), carriage return (\r), form feed (\f), backspace (\b), and any Unicode control character using \uXXXX notation. JavaScript's JSON.stringify() handles this automatically. This tool performs the same escaping entirely in your browser.
< becomes <) so they display as visible text in web pages instead of being interpreted as markup. URL encoding (percent-encoding) converts characters to %XX format (e.g., a space becomes %20) so they can be safely included in URLs. They serve different purposes and are not interchangeable — HTML encoding prevents markup injection in pages, while URL encoding ensures characters are transmitted correctly in URLs.
\n with a newline, \t with a tab, \" with a double quote, \\ with a single backslash, and \uXXXX with the corresponding Unicode character. This tool handles all standard escape sequences automatically. In JavaScript, JSON.parse() can unescape JSON-style escaped strings when the input is wrapped in double quotes.
All tools run in your browser, no signup required, nothing sent to a server.