Escape or unescape a string for JS/JSON string literals instantly in your browser.
Updated
/ 5 - Be the first to rate this tool Thanks for rating!
Verification failed - please try again.
Quick check
Please verify you're not a robot to submit your rating.
Give feedback
Tell us what you think about Escape or unescape a string online.
- Runs entirely in your browser — your text is never sent to a server
- Escape or unescape for JS/JSON string literals
- Free, no account required
How it works
-
1
Choose Escape or Unescape.
-
2
Paste your text into the Input box.
-
3
Press the button to convert it.
-
4
Copy the output into your code.
About the String Escape/Unescape
Putting text inside a string literal means escaping its quotes, backslashes and line breaks, and reading an escaped string from a log means undoing that by hand. This tool escapes text using JSON string rules, which JavaScript and many other languages share, and unescapes sequences like \n, \t, \" and \u00e9 back into the characters they represent.
What you can do
- Escape text so double quotes become \", backslashes become \\ and line breaks become \n.
- Escape tabs, carriage returns and other control characters into their short or \u forms.
- Unescape a string, turning \n, \t, \" and \uXXXX sequences back into real characters.
- Swap the output into the input to reverse the operation and check the result.
When it works best
- Pasting a multi-line message or SQL query into a JSON value or a JavaScript string.
- Reading an error message from a log where every newline appears as \n.
- Preparing a test fixture that needs quotes and backslashes inside a string.
Things to know
- Escaping and unescaping run in your browser.
- The output uses JSON rules and does not include the surrounding quotes. Single quotes are not escaped, so add escapes yourself for single-quoted strings.
- Unescape rejects sequences JSON does not allow, such as \x41 or a bare backslash, and reports the input as invalid.
- For HTML text use HTML Entity Encode/Decode, and for URL parameters use URL Encode/Decode.
Frequently asked questions
JSON string rules, which JavaScript and many other languages share.
No, and surrounding quotes are not added.
Sequences JSON does not allow, such as \x41 or a lone backslash, are rejected.
Use HTML Entity Encode/Decode.