Text
String Escape
Escape text into a string literal (quotes, backslash, control characters) for pasting into code, or unescape it back.
To put text containing quotes, line breaks, or backslashes inside a string literal in code, those characters need escaping — otherwise they'll end the string early or get misinterpreted. This tool escapes and unescapes text for a specific syntax.
How to use it
- Escape: paste text and pick a target context (a JS string, JSON, shell, etc.) and special characters get replaced with the matching escape sequences.
- Unescape: paste an already-escaped string to get the original text back.
- Different contexts escape the same character differently — make sure you've picked the mode matching where the text will actually be inserted.
Common uses
- Inserting multi-line text or text with quotes into a code variable without manually placing backslashes.
- Preparing a string for a shell command, where quotes and special characters can break execution.
- Unescaping a string copied from logs or a JSON response to read the original text.
Things to keep in mind
The same character (a double quote, for example) is escaped differently depending on context — a JS string, JSON, and a shell each have their own syntax and their own set of special characters.
Double-escaping (escaping already-escaped text) is a common mistake when passing data through multiple layers, like JSON nested inside a shell command.
Article about this tool: String Escape: why the same text needs escaping differently
Frequently asked questions
What exactly does escaping do?
It turns quotes, backslashes, and control characters (like line breaks or tabs) into valid escape sequences within a string literal, so the text can be pasted as-is into source code.
What are the quote style and unicode options for?
The quote style (double, single, or backtick) determines which character is escaped so it doesn't break the string, and the \uXXXX option converts non-ASCII characters into escaped unicode sequences rather than leaving them as-is.
Is the pasted text sent to a server?
No, escaping and unescaping run entirely in the browser via JavaScript, no data is sent online.
What if the text passes through several contexts in a row?
Escaping needs to happen in the right order: first for the inner context (say, JSON), then for the outer one (say, the shell command that this JSON gets inserted into). Getting the order wrong or skipping a level is a common reason a "properly escaped" string still breaks in practice.
Why is the same quote character escaped differently in different contexts?
Each context (a JS string, JSON, shell, regex) has its own syntax with its own set of special characters and its own way of escaping them — so correct escaping depends on where exactly the text is being inserted, not on the text itself.