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\nand\t, and other control characters become short escapes such as\bor\u0000codes. Accented letters, emoji and single quotes are left as they are, because JSON allows them. - Generic escapes backslashes, double quotes,
\n,\r,\tand the null character\0, and writes other control characters as\u0000codes. 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\bor\x41, is listed in a warning and kept without its backslash. - Double escaping: text escaped twice shows
\\ninstead 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.