String Escape and Unescape
Prepare text to paste inside a string literal β or turn escaped text back into readable text β for JSON, JavaScript, SQL, CSV, regex, Unicode escapes and XML.
Result
Paste text to escape or unescape it.
How to use this tool
- Choose Escape or Unescape and a format.
- Paste the text. The result updates as you type.
How it works
- JSON: quotes, backslashes and control characters become
\",\\,\nand so on. - JavaScript: as JSON, plus single quotes, backticks and
${so the text is safe in any kind of quotes. - SQL: single quotes are doubled (
O''Brien). - CSV: the value is wrapped in double quotes and inner quotes are doubled.
- Regex: characters such as
. * + ? ( ) [ ]get a backslash so they match literally. - Unicode: non-ASCII characters become
\uXXXX. - XML:
& < > " 'become entities.
Example
SQL
O'Brien escaped for SQL is O''Brien.
Regex
1.5*(x) escaped for a regular expression is **1\.5\*\(x\)**.
Privacy and limitations
- Everything runs in your browser; nothing you paste is uploaded or stored.
- Escaping for SQL is no substitute for parameterised queries, which prevent SQL injection properly.
Frequently asked questions
Why does unescaping JSON fail?
The text must be the inside of a valid JSON string: quotes and backslashes must already be escaped, and line breaks written as \n.
How are emoji escaped?
As two \u escapes (a surrogate pair), as JSON and JavaScript require: π becomes \uD83D\uDE00.