Escape Text for Special Characters

Paste your text on the left and instantly get escaped text on the right.

I want to:
Format:

Frequently asked questions

Which characters get escaped?

It depends on the format. JavaScript / general escapes backslashes, both quotes, newlines, carriage returns, tabs, \0 \b \f \v, other control characters as \xHH, and the line and paragraph separators U+2028 and U+2029. JSON string does exactly what JSON.stringify does and leaves single quotes alone. SQL doubles single quotes. CSV doubles double quotes and wraps the field in quotes.

When do I need escaped text?

Whenever a string has to survive being embedded in code or data: a JavaScript string, a JSON value, a SQL literal or a CSV field.

Why is my backslash doubled?

The backslash is the escape character itself, so it has to be escaped to survive as a literal backslash. One backslash in becomes two out.

What is the difference between escaping and URL encoding?

Escaping adds backslashes so a string survives inside code. URL encoding turns characters into percent codes so they survive inside a web address. They solve different problems and are not interchangeable.

Is this the same as HTML encoding?

No. Escaping adds backslashes for code contexts. HTML encoding turns characters into entities for use in markup, which is what the HTML Entity Encoder is for. And if your quotes are curly rather than straight, escaping will not save the string: run it through the Smart Quote Converter first.

Can I unescape text again here?

Yes. Switch to Unescape and pick the same format. It reads \n \r \t \\ \' \" \0 \b \f \v, \xHH, \uHHHH and \u{...}. An unknown escape such as \q keeps just the letter.

Why does my JSON break on a backslash before an apostrophe?

JSON has no \' escape, so a string escaped for JavaScript can fail to parse as JSON. Choose JSON string and single quotes are left as they are.