About the String Escape / Unescape
This string escape tool converts raw text into a correctly escaped literal for the language or format you are pasting it into, and reverses the process to turn escaped strings back into readable text. It handles JSON strings, JavaScript and TypeScript strings (single, double or backtick quotes), standard SQL string literals, CSV fields, regular-expression literals, POSIX shell arguments and XML or HTML text.
Use it when you need to embed a multi-line message in a JSON payload, paste a file path containing backslashes into code, put a name like O’Brien into a SQL query, quote a CSV cell that contains commas, match a literal "$9.99 (USD)" with a regex, or decode an escaped log line full of \n and \u00e9 sequences. It shows how many characters were changed so you can see exactly what happened.
Escaping is about syntax, not security: for SQL always prefer parameterised queries, and for HTML output use your framework’s auto-escaping. The SQL mode follows the ANSI standard (a quote is doubled); MySQL’s optional backslash escapes are not applied. Everything runs locally in your browser.
How to use the string escape / unescape
- 1Paste the text you want to convert.
- 2Choose Escape to make it safe for a literal, or Unescape to decode it.
- 3Pick the target format: JSON, JavaScript, SQL, CSV, regex, shell or XML.
- 4For JavaScript choose the quote style, and optionally wrap the result in quotes.
- 5Copy the result into your code, query or file.
Formula and method
Each format has its own reserved characters. JSON (RFC 8259) requires escaping the double quote, the backslash and control characters below U+0020 (written as \n, \t, \r, \b, \f or \u00XX). JavaScript adds the chosen quote character, \v, \0, \xHH for other control characters, U+2028/U+2029, and ${ in template literals. SQL doubles single quotes; CSV (RFC 4180) wraps fields containing commas, quotes or line breaks in double quotes and doubles embedded quotes.
Regex escaping puts a backslash before every metacharacter . * + ? ^ $ { } ( ) | [ ] \ /. Shell escaping wraps the string in single quotes and rewrites each embedded quote as '\''. XML replaces & < > " ' with entities. Unescaping reverses these rules and reports malformed input, such as a broken \u escape, instead of guessing.
Worked examples
Escape a multi-line message for JSON
Two double quotes become \", the line break becomes \n, the tab becomes \t and each of the two backslashes in the Windows path is doubled. That is six extra characters: 38 characters in, 44 out.
Put a surname into a SQL literal
Standard SQL escapes a single quote by doubling it, so each of the two apostrophes becomes ''. Wrapping adds the surrounding quotes, giving 'O''Brien''s cafe' — four characters longer than the input.
Decode an escaped log line
JSON unescaping turns \u00e9 into é, \u2013 into an en dash, \" into a quote, \n into a line break and \t into a tab, recovering the original 20-character text.
Escape a price for a regex
The dollar sign, the dot and both parentheses are regex metacharacters, so each gets a backslash; the pattern now matches the literal text "$9.99 (USD)".
Frequently asked questions
How do I escape a double quote in JSON?+
Put a backslash in front of it: \". Backslashes themselves must be doubled (\\), and line breaks, tabs and other control characters must be written as \n, \t or \u00XX because raw control characters are not allowed inside JSON strings.
How do I escape a single quote in SQL?+
Double it: 'O''Brien' stores O'Brien. This is the ANSI SQL rule supported by PostgreSQL, SQL Server, Oracle, SQLite and MySQL. Better still, pass values as query parameters so no escaping is needed.
How do I escape a comma in a CSV file?+
Wrap the whole field in double quotes, for example "Smith, John". If the field itself contains a double quote, write it twice inside the quotes: "He said ""hi""". This follows RFC 4180, which Excel and Google Sheets understand.
What is the difference between escaping and encoding?+
Escaping adds markers such as backslashes so special characters are read literally inside one syntax (a JSON string, a regex). Encoding, like URL encoding or Base64, transforms the whole text into a different representation for transport.
Why does my unescaped JSON show an error?+
The input contains a sequence JSON does not allow, such as a single backslash before an ordinary letter (\q), an incomplete \u escape, or an unescaped double quote. Fix that character or try the JavaScript format, which is more lenient.