Skip to content
codinganthem
All tools/Encoders/String Escape / Unescape

String Escape / Unescape

Escape or unescape strings online for JSON and code: quotes, backslashes, \n, \t and Unicode escapes. Free, instant, and it runs in your browser.

More
Buy me a coffee

How to escape a string online

Choose Escape and paste the text, then pick a style. Choose Unescape to turn an escaped string from a log, an API response or source code back into the real characters. Results update as you type.

Text:     He said "hello" (followed by a line break)
Escaped:  He said \"hello\"\n

Generic and JSON escaping

  • JSON escapes exactly what a JSON string requires, using the same rules as JSON.stringify: double quotes, backslashes and control characters. Line breaks and tabs become \n and \t, and other control characters become short escapes such as \b or \u0000 codes. Accented letters, emoji and single quotes are left as they are, because JSON allows them.
  • Generic escapes backslashes, double quotes, \n, \r, \t and the null character \0, and writes other control characters as \u0000 codes. Use it for string literals in JavaScript, Java, C# and similar languages.
  • Neither style escapes single quotes. If your string is wrapped in single quotes in code, escape ' yourself.

Unescaping and common mistakes

  • Unescape understands \\, \n, \r, \t, \0, \", \' and \uXXXX. Anything else, such as \b or \x41, is listed in a warning and kept without its backslash.
  • Double escaping: text escaped twice shows \\n instead of \n. Unescape it twice to get the original back.
  • Single quotes aren't valid around JSON strings. Use double quotes, and check the result with the JSON Formatter.
  • This tool is for string literals. For URLs use the URL Encoder, and for HTML use HTML Entities.

Frequently asked questions

How do I escape a string for JSON?+

Choose Escape and the JSON style, then paste the text. Quotes, backslashes, line breaks, tabs and other control characters are escaped exactly as JSON requires.

What does \n mean in a string?+

It's an escaped line break. Unescaping turns \n back into a real new line, and \t into a tab.

Why do I see \\n instead of \n?+

The text was escaped twice. Unescape it twice, or escape the original text only once.

Does it escape single quotes?+

No. JSON doesn't need them escaped, and the generic style leaves them too, so escape ' yourself if your string is wrapped in single quotes.

Is my text sent anywhere?+

No. Escaping and unescaping run in your browser.