What is String Escape/Unescape Tool?
String Escape/Unescape is a free online tool that converts special characters into safe representations for different programming contexts, and reverses the process. Every programming language and data format has characters with special meaning that must be escaped to be used literally. A newline becomes \n in JavaScript, angle brackets become < and > in HTML, and spaces become %20 in URLs. Incorrect escaping leads to syntax errors, broken data, and security vulnerabilities like cross-site scripting (XSS) and SQL injection. This tool supports five escape modes: JavaScript, JSON, HTML, URL, and CSV.
How to Use This Tool
Select the escape mode (JavaScript, JSON, HTML, URL, or CSV) and the direction (Escape or Unescape). Type or paste your string into the input area. The output updates in real time as you type. Character count statistics show the input and output lengths with the difference highlighted. Copy the result with one click. Switch between modes to see how the same string is escaped differently across formats.
Common Use Cases
- Escaping strings for embedding in JavaScript source code or JSON data files
- Converting user-generated content to HTML-safe entities to prevent XSS attacks
- Encoding query parameters and path segments for URLs
- Preparing text fields for CSV export with proper quoting and double-escape handling
Why Use a Client-Side Tool?
All escaping and unescaping happens entirely in your browser. Your strings are never sent to any server, making it safe to process API keys, authentication tokens, personal data, and other sensitive content. The tool requires no account, works offline after the page loads, and handles Unicode characters including emoji and multi-byte sequences correctly.
Frequently Asked Questions
What is the difference between JavaScript and JSON escaping?
JavaScript escaping handles single quotes, backticks, and template literal syntax in addition to double quotes. JSON escaping follows the stricter RFC 8259 specification, which also escapes forward slashes and does not support single quotes or backticks since JSON only uses double-quoted strings. Use JSON mode when preparing data for JSON files and API payloads.
When should I use URL encoding?
URL encoding (percent-encoding) should be used whenever you include user input or special characters in URL query parameters, path segments, or fragment identifiers. Characters like spaces, ampersands, equals signs, and non-ASCII characters must be encoded to form valid URLs. The tool uses the standard encodeURIComponent function, which encodes all characters except unreserved ones (A-Z, a-z, 0-9, -, _, ., ~).
How does CSV escaping work?
CSV escaping follows RFC 4180. Fields containing commas, double quotes, or newlines are wrapped in double quotes. Any double quotes within the field are doubled (escaped as two consecutive double quotes). When unescaping, the tool reverses this process by removing the outer quotes and converting doubled quotes back to single ones.