About String Escaper & Unescaper Tool
Escape strings online, or unescape them, so text can be placed safely inside code and data formats: JavaScript/JSON, Python, Java/C++, C#, HTML entities, XML, URL encoding, SQL string literals, regular expressions and shell (Bash) commands. Choose the target, escape or unescape, and swap input and output to reverse.
How to use it
- 1Paste your string or code snippet.
- 2Select target syntax (JavaScript, JSON, Java, SQL, etc.).
- 3Click Escape or Unescape to copy safe string literals.
Why escaping is needed
Each language has characters with special meaning — quotes end a string, backslashes start escape sequences, < starts a tag. To use them as plain text, they must be escaped.
| Target |
Text |
Escaped |
| JavaScript / JSON |
He said "hi" + new line |
He said \"hi\"\n |
| Python |
C:\new\folder |
C:\\new\\folder (or raw string r"C:\new\folder") |
| HTML |
<b>Tom & Jerry</b> |
<b>Tom & Jerry</b> |
| SQL |
O'Brien |
O''Brien |
| Regex |
price: $5.00 (USD) |
price: \$5\.00 \(USD\) |
| Shell |
it's here |
'it'\''s here' |
| URL |
a b&c |
a%20b%26c |
Common escape sequences
\n new line · \t tab · \r carriage return · \\ backslash · \" double quote · \uXXXX Unicode character.
Security note
Escaping SQL strings by hand is not a safe way to stop SQL injection. In application code, always use parameterised queries (prepared statements). Likewise, use your framework's built-in escaping for HTML output. Use this tool for one-off snippets, test data and debugging.
Escaping rules differ by language
The same text needs different escaping depending on where you put it:
| Context |
Example of escaping a quote and a newline |
| JSON |
"He said \"hi\"\n" |
| JavaScript |
'It\'s' or a template literal `It's` |
| Python |
"Line 1\nLine 2" or a raw string r"C:\path" |
| SQL |
'O''Brien' (quote doubled) |
| CSV |
"He said ""hi""" (quote doubled) |
| Regex |
\. \* \( to match the character literally |
When text passes through several layers — for example a regex inside a JSON string — each layer needs its own escaping, which is why backslashes multiply.
Windows paths and backslashes
A Windows path like C:\new\test.txt breaks in many languages because \n and \t are read as newline and tab. Fixes:
- Double the backslashes:
"C:\\new\\test.txt".
- Use forward slashes, which Windows also accepts in most programs:
"C:/new/test.txt".
- In Python, use a raw string:
r"C:\new\test.txt".
Escaping vs parameterising
Escaping is handy for writing literals by hand — a path in a config file, a quote in a JSON value, a regex in code. For data that comes from users, don't build SQL or shell commands by escaping strings yourself: use parameterised queries and argument arrays, which are safe by design. Test escaped regex patterns in the regex tester, and for HTML content use the HTML encoder.
Frequently Asked Questions
What does escaping a string do?
It adds escape characters, usually a backslash, before characters that would otherwise end the string or have a special meaning, such as quotes and line breaks.
What does unescaping do?
The reverse: it turns sequences like \n and \" back into a real line break and a quote.
How do I escape a string for JSON?
Choose JavaScript / JSON and click Escape. Double quotes become \", backslashes become \\ and line breaks become \n.
How do I escape a single quote in SQL?
Double it: 'It''s'. Better still, use parameterised queries so you never build SQL from user input.
How do I escape special characters in a regex?
Choose Regex Pattern. Characters such as . * + ? ( ) [ ] { } ^ $ | get a backslash so they match literally.
How do I escape a Windows file path?
In most languages, double each backslash: C:\\Users\\Name. In Python you can also use a raw string, r"C:\Users\Name".
Why are there so many backslashes in my escaped string?
The text was probably escaped more than once. Unescape it until it looks right, then escape it once.
Is escaping the same as encrypting?
No. Escaping only makes text safe to place in code or data; anyone can reverse it. It does not hide information.
Explore Related Free Online Tools