Tool guide
About this tool.
- String literals reserve some characters: the quote that ends the literal, the backslash that starts an escape, and control characters such as newlines. Escaping rewrites them so the text can sit safely inside source code, a query, a document or a command line.
- Each language has its own rules, so text escaped for JSON is not always valid for SQL or a shell. Everything runs locally in your browser or editor.
- JSON, JavaScript and Java use backslash escapes: \" \\ \n \t and \uXXXX for control characters. JavaScript also escapes the single quote. SQL doubles the single quote. Regex puts a backslash before special characters. XML uses entities such as & and <.
- A CSV field is wrapped in double quotes when it contains a comma, a quote or a line break, and inner quotes are doubled. POSIX shell escaping wraps the text in single quotes and rewrites each inner single quote as '\''.
Pick the target language, choose Escape or Unescape and paste your text.
In Escape mode the result can be used inside a literal of that language. For JSON, JavaScript, Java and SQL you can also wrap it in quotes.
In Unescape mode the tool reverses the escaping and points to the first problem, for example Invalid escape \q at position 5.
The summary shows the direction, the language and the number of input characters.
- JSON: He said "hi" → He said \"hi\"
- JavaScript: it's → it\'s
- SQL: O'Reilly → O''Reilly
- Regex: a.b*c? → a\.b\*c\?
- XML: <a & b> → <a & b>
- Shell: it's → 'it'\''s'
- Input is limited to 1,000,000 characters.
- JSON, JavaScript and Java share the same core escapes; JavaScript adds \v, \0, \xHH and \u{...}, and Java adds \s on input.
- Legacy octal escapes such as \012 are rejected on unescape.
- Shell unescape reads one word made of single quotes, double quotes and backslash escapes.
- SQL unescape reads text whose quotes are all doubled as escaped text and keeps the outer pair, so that Escape output always reverses: '' becomes ' and '''' becomes ''. Surrounding quotes are removed only when the text would otherwise have a lone quote.
- A single newline at the end of the input does not stop surrounding quotes from being removed.