String Escape / Unescape
Escape or unescape strings for JSON, JavaScript, HTML, URL, CSV, and RegEx contexts — instantly.
Last updated: March 25, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is String Escape / Unescape?
String escaping is the process of adding a special prefix character (usually backslash or percent) before characters that have special meaning in a specific context, so that they are treated as literal characters rather than control characters. The escape characters, rules, and which characters need escaping differ completely between contexts: JSON, JavaScript strings, HTML attributes, URL query parameters, CSV cells, and regular expressions each have their own distinct escaping rules.
Choosing the wrong escaping context — or forgetting to escape at all — causes everything from irritating rendering bugs to critical security vulnerabilities (SQL injection, XSS, path traversal). This tool provides side-by-side escaping for all major string contexts, so you can pick the right format whether you're writing an API payload, constructing a query string, embedding text in HTML, or building a regex pattern.
How to Use String Escape / Unescape
Type or paste your raw text string into the input field
Select the escaping context from the tabs: JSON, JavaScript, HTML, URL, CSV, or RegEx
Click "Escape" to convert the raw string to its escaped form
Or paste an escaped string and click "Unescape" to decode it back to the original
Copy the result with the Copy button for use in your code or query
Common Use Cases
- JSON-escaping strings before embedding them in JSON payloads (newlines, quotes, backslashes)
- URL-encoding query parameter values before appending to an API endpoint URL
- Escaping regex metacharacters (. * + ? [ ] { } ( ) | ^ $) when constructing regex from user input
- HTML-escaping user input before displaying it in a web page (XSS prevention)
- CSV-escaping text fields containing commas or double-quotes before writing to a CSV file
- JavaScript string escaping for embedding variables into template literals or string concatenation
- Unescaping percent-encoded URLs from logs or error messages to read them clearly
- Decoding JSON-escaped strings from API responses to inspect the raw content
Example Input and Output
The same string escaped differently for four different contexts:
She said "It's $10 < tax" & left.JSON: "She said \"It's $10 < tax\" & left."
JavaScript: 'She said "It\'s $10 < tax" & left.'
HTML: She said "It's $10 < tax" & left.
URL: She%20said%20%22It's%20%2410%20%3C%20tax%22%20%26%20left.
CSV: "She said ""It's $10 < tax"" & left."
RegEx: She said "It's $10 < tax" & left.Privacy First
All escaping and unescaping runs locally in your browser. Your strings — which may contain API keys, passwords, or sensitive data — are never sent to our servers.
Context Matters for Security
Using the wrong escaping context is a security vulnerability. HTML-encoding a value placed into a JavaScript string doesn't prevent JS injection. URL-encoding a value placed in HTML doesn't prevent XSS. Always escape using the rules for the exact output context in which the string will appear.
Language Built-Ins
In production code, use your language's built-in functions rather than manual escaping: JavaScript URL: encodeURIComponent(). JavaScript JSON: JSON.stringify(). Python HTML: html.escape(). Python URL: urllib.parse.quote(). PHP HTML: htmlspecialchars(). PHP URL: urlencode(). Library functions handle edge cases that manual escaping misses.
Frequently Asked Questions
What characters need escaping in JSON strings?
What is the difference between URL encoding and HTML encoding?
How do I escape a string for use inside a JavaScript template literal (backtick)?
How do I escape a CSV field that contains commas or quotes?
Which regex characters need escaping?
Why does JavaScript have both escape() and encodeURIComponent()?
How This Tool Works
Each escaping mode applies a context-specific transformation: JSON escaping uses JSON.stringify() and extracts the inner content with quote stripping. JavaScript escaping applies backslash rules using regex replacements per the ECMAScript specification. HTML escaping uses the browser's innerHTML/textContent technique (for decoding) and a character map (for encoding). URL escaping uses encodeURIComponent() built-in. CSV escaping wraps in quotes and doubles internal quotes per RFC 4180. RegEx escaping escapes all metacharacters using a standard metacharacter set regex.
Technical Stack