String escape and unescape

Paste some text and get the version with special characters protected for JSON, JavaScript, Python, regex, shell, SQL, CSV, Java/C# or PHP, or go the other way round. Errors in escape sequences are reported with their position.

Your data stays on your computer. Files are processed in your browser and are never uploaded.

Format
Direction

Content of a JSON string: \n \t \" \\ and \uXXXX for control characters. No outer quotes unless you turn the option on.

0 characters

Options

Result

Paste some text to see the result.

Keyboard shortcuts

In this tool

This tool has no keyboard actions.

Everywhere

Open this panel (outside text fields)
?
Closes panels and menus, never clears data
Esc
Search for a tool
/ or CtrlK

How to use it

  1. Pick the target format (JSON, JavaScript, Python, regex, shell, SQL, CSV, Java/C# or PHP) and the direction: Escape to protect the text, Unescape to bring it back to plain form.
  2. Paste the text into the box: the result appears right away and updates as you type. The options (quote, outer quotes, non-ASCII characters, CSV separator) change with the format.
  3. When unescaping, if a sequence is wrong (for example a truncated \u12) you get the error with its position, line and column, and nothing is changed.
  4. Copy the result, or use "Swap direction using the result" to check the way back: you should get the original text again.

Frequently asked questions

Why are there no outer quotes in JSON?

Usually you paste the text inside a string already written in your code or in a JSON file, so only the protected characters are needed. If you need the whole string, turn on "With the outer quotes".

Does SQL escaping protect against SQL injection?

No. Doubling quotes is fine for pasting a value into a hand-written query, but it does not cover every case (special encodings, backslashes in MySQL, unquoted numbers). In real code use parameterised queries.

How are emoji and characters outside the Unicode base plane handled?

They are left untouched unless you turn on writing non-ASCII characters as escapes: then in JSON, JavaScript and Java they become a pair of \uXXXX (surrogates), in Python \UXXXXXXXX and in PHP \u{XXXXX}. When unescaping, both pairs and \u{1F600} are read.

What is the difference between single and double quotes in PHP?

In single quotes PHP only interprets \' and \\: a \n stays two characters. In double quotes it interprets \n \t \$ and the other sequences, and substitutes variables: that is why the $ must be protected.

What does the tool do with unknown backslashes when unescaping?

It depends on the language, just like the language itself: JSON and Java give an error, JavaScript drops the backslash, Python and PHP keep it. For regular expressions only the backslashes before metacharacters are removed.

Privacy

Everything happens in your browser: no text is sent or saved. The share link includes the text only if it is short and in the part after the # of the address, which never reaches the server.

Tool chains

Link several tools into a path: after using a tool, “Send to…” offers the next step first. Saved chains keep only a name and the tools, never your data.

Saved chains

No saved chains.

New chain