String escape and unescape

Make text safe to paste inside a string literal, or turn an escaped string back into readable text. Pick the language, and the rules follow.

32 chars
36 chars

Why strings need escaping

A string literal is delimited by quotes, so a quote inside it would end the string early. The backslash tells the parser “the next character is special”: \" is a literal quote, \n a newline, and \\ a real backslash. Unescaping reverses the process.

Each language has slightly different rules. JSON is the strictest: no single-quote strings, no \x, and every control character must be escaped. SQL doesn't use backslashes at all; it doubles the quote. Regex escaping is different again: it protects characters like . * ? ( ) that have meaning in a pattern.

For HTML use the HTML entity encoder, and for URLs the URL encoder.

Questions people ask

How do I escape a string for JSON?

Choose JSON and paste the text. Double quotes become \", backslashes become \\, and newlines, tabs and other control characters become \n, \t or \u00XX, exactly as JSON.stringify produces (RFC 8259).

How do I unescape a string?

Choose Unescape and the language the string came from. Sequences such as \n, \t, \", \u00e9, \x41 and \u{1F600} are turned back into the real characters.

What is the difference between JSON and JavaScript escaping?

JSON only allows double-quoted strings and a fixed set of escapes. JavaScript also escapes single quotes (so the string works in either quote style) and supports \x and \u{…} forms.

How do I escape a single quote in SQL?

Double it: O’Reilly becomes O''Reilly inside a quoted literal. Prefer parameterised queries in real code, which remove the need to escape at all.

What does “ASCII only” do?

It also escapes every non-ASCII character as \uXXXX (or \U… in Python), so the result survives systems that mangle UTF-8.