String Escape / Unescape
Escapes special characters in a string for JavaScript, JSON, CSV, SQL or regex, or reverses the process. An option can turn non-ASCII characters into unicode escapes.
Use the tool
Why this tool exists
Quotes, backslashes and newlines cause bugs in the places you least expect. A pasted error message breaks a JavaScript string literal, a CSV cell with a comma splits into two columns, and a SQL value containing an apostrophe either fails or opens the door to injection. Each language has its own rules, and remembering them under pressure is unreliable.
This tool applies the right rule for the format you pick and can undo it as well, which helps when you are reading a log full of backslashes. Everything is processed in your browser, so you can paste real payloads without sending them to a server. For SQL, treat it as a quick helper rather than a replacement for parameterised queries.
How to use it
- Paste your string into the input box.
- Pick a format: JavaScript, JSON, CSV, SQL or Regex.
- Choose escape or unescape, and tick Escape non-ASCII if you want unicode escapes.
- Copy the result from the output.
Frequently asked questions
What does each format escape?
JavaScript escapes quotes, backticks, backslashes and control characters. JSON uses the standard JSON string rules. CSV wraps the value in double quotes and doubles inner quotes. SQL doubles single quotes. Regex adds a backslash before special characters.
Does escaping for SQL make my query safe?
No. Doubling apostrophes is only a basic aid for writing a literal by hand. For anything that takes user input, use parameterised queries or prepared statements in your database library instead.
Why does unescaping fail with an error?
The JSON mode expects a valid JSON string body, so a stray backslash or a bad unicode escape raises an error. JavaScript mode also reports an invalid code point. Check the input for half-written escapes.
What does Escape non-ASCII do?
For JavaScript and JSON it replaces characters outside the ASCII range with unicode escapes, such as an e with an accent becoming a four-digit escape. This helps when a file must stay pure ASCII.