String Escape and Unescape

Paste the text, choose the language, then pick Escape or Unescape. Escape adds the backslashes or doubled quotes that the language needs, and can write non-ASCII characters as \u escapes. Unescape reverses the process and reports the position of an invalid escape. For JSON there is also a Stringify option that wraps the whole text in double quotes.

String Escape and Unescape runs entirely in your browser: the text you paste is never sent to a server. It is free and needs no sign-up.

How to use it

  1. Choose the language In String Escape and Unescape, choose the language the text will go into, such as JSON, Python, SQL or Regular expression literal.
  2. Escape or unescape Press Escape to add backslashes or other markers, or Unescape to reverse them. Tick Convert non-ASCII characters when the target code must be plain ASCII. The option is off for languages that do not use it.
  3. Find the error position If an escape is wrong, the message gives its character number. In JSON mode, Stringify wraps the whole text in quotes, and Unstringify reads one quoted string.

Questions

Why do the rules differ between languages?

Most languages use backslashes for escapes, but SQL doubles a single quote instead. Check the target language before you copy the result, because one rule does not fit all.

Why does Unescape say the input is not a JSON string?

A JSON string must start and end with double quotes and contain only valid escapes, such as a line break or a tab. Use JSON mode with the whole string option when the quotes belong to your text.