String Escaper
Developer Tools · Added
Six formats, six different sets of rules, and no two of them agree. JSON has no single-quoted strings; a shell has no escape character at all inside single quotes; CSV doubles its quote rather than prefixing it. Paste your text, pick where it is going, and get back something that will survive the journey.
How to use the string escaper
- 1Choose whether you are escaping text or reversing an escape.
- 2Pick the target — the box below the selector explains what that target's rules actually are.
- 3Paste your text.
- 4Copy the result, and check the length change if the value has to fit a column limit.
Examples
A quoted phrase into JSON
- Input
- He said "hello" then left
- Result
- "He said \"hello\" then left"
An awkward filename into a shell command
- Input
- Bob's file; rm -rf /
- Result
- 'Bob'\''s file; rm -rf /'
Single quotes stop the shell expanding anything, so the semicolon and the command after it are inert text.
About the string escaper
Escaping is about the destination, not the text
The same string needs different treatment depending on where it lands. A newline becomes \n in JSON, stays a literal newline inside CSV quotes, and needs no attention at all in a shell single-quoted string. A double quote is critical in JSON and irrelevant in SQL. There is no such thing as a generally escaped string.
That is why this asks for the target first. Picking the wrong one produces output that looks escaped and breaks anyway — which is worse than not escaping at all, because it looks handled.
Round-tripping is not always possible
Escaping is a function; unescaping is not always its inverse. In JavaScript a backslash before a character with no defined escape simply yields that character, so \q and q both unescape to the same thing and the original cannot be recovered. In CSV, a field that needed no quoting and one that was quoted unnecessarily decode identically.
Where an escape is ambiguous this tool takes the conventional reading rather than guessing at intent, and it reports a genuinely malformed input — a string ending in a lone backslash, a \u with three hex digits — instead of silently producing something plausible.
Frequently asked questions
Does the SQL option protect against injection?
Why does the shell option produce that odd sequence of quotes?
When would I want the ASCII-only option?
Why is HTML not one of the targets?
Related tools
JSON Formatter
Developer Tools
Pretty-print, minify and inspect JSON with precise error positions.
URL Encoder / Decoder
Developer Tools
Percent-encode and decode URLs and query parameters, with a query string breakdown.
Regex Tester
Developer Tools
Test regular expressions live with highlighted matches, capture groups and replace.