What this tool does
Escaping rewrites characters that have a special meaning in one place so they are read as plain text instead. This tool escapes and unescapes text for eight contexts: JSON strings, JavaScript strings, plain Unicode escapes, HTML, URLs, CSV fields, regular expressions and shell arguments. Pick the context first, because that decides which characters matter and what they become. The table under the tool shows your text in every context at once.
It only escapes. It does not validate, sanitize or remove anything, and it does not check that the result is safe to use in a particular place. See the security section below.
Why one escaping does not fit everywhere
Every escaping rule exists because some parser will read the text later, and that parser has its own special characters. A double quote ends a JSON string, a & starts an HTML entity, a % starts a percent escape, a comma splits a CSV field, a . matches any character in a regular expression, and a single quote is the only thing that matters inside a POSIX shell string. Text escaped for one parser is wrong for another. HTML-escaped text pasted into a JSON string still contains raw quotes, and a URL-encoded value put into CSV is only less readable.
The same input, He said "hi" & left C:\temp, in each context:
| Context | Result |
|---|---|
| JSON string | He said \"hi\" & left C:\\temp |
| JavaScript string | He said \"hi\" & left C:\\temp |
| Unicode escapes | He said "hi" & left C:\\temp |
| HTML text and attributes | He said "hi" & left C:\temp |
| URL component | He%20said%20%22hi%22%20%26%20left%20C%3A%5Ctemp |
| CSV field | "He said ""hi"" & left C:\temp" |
| Regular expression | He said "hi" & left C:\\temp |
| Shell argument | 'He said "hi" & left C:\temp' |
Note how the backslash is doubled in JSON, JavaScript and regex, left alone in HTML, percent-encoded in a URL, and kept literally inside shell single quotes.
Special characters by context
What each character becomes, using the default options of this tool. “Unchanged” means that character needs no escaping in that context.
| Character | JSON | JavaScript | HTML | URL component | Shell (inside single quotes) |
|---|---|---|---|---|---|
| Double quote | \" | \" | " | %22 | unchanged |
| Single quote | unchanged | unchanged | ' | unchanged | '\'' |
| Backslash | \\ | \\ | unchanged | %5C | unchanged |
| Newline | \n | \n | unchanged | %0A | unchanged |
| Tab | \t | \t | unchanged | %09 | unchanged |
| & | unchanged | unchanged | & | %26 | unchanged |
| < | unchanged | unchanged | < | %3C | unchanged |
| Space | unchanged | unchanged | unchanged | %20 | unchanged |
| % | unchanged | unchanged | unchanged | %25 | unchanged |
| Accented letter (é) | unchanged | unchanged | unchanged | %C3%A9 | unchanged |
| Emoji (😀) | unchanged | unchanged | unchanged | %F0%9F%98%80 | unchanged |
- Quotes. Only the quote that delimits the string must be escaped. JSON strings use double quotes only. A JavaScript string can use either, or backticks for template literals, and the tool escapes the one you choose.
- Backslashes. The backslash starts every escape sequence, so it must be doubled first. Forgetting this is the most common cause of broken Windows paths and regular expressions in code.
- Newlines and tabs. JSON and JavaScript cannot contain a raw line break in a normal string, so they become
\nand\t. In HTML a line break is only whitespace. In CSV a line break is allowed inside a quoted field. In a shell single-quoted string it is kept as typed. In a URL it is%0A. - Control characters. JSON requires everything below U+0020 to be escaped, as
\b \f \n \r \tor\u00XX. JavaScript output uses\xNNfor the others.
Unicode and non-ASCII text
JSON and JavaScript sources are normally UTF-8, so accented letters and emoji can stay as they are. Tick Escape all non-ASCII characters when the text must pass through something that is not UTF-8 safe, such as an ASCII-only file, log or configuration. Characters above U+FFFF are written as a UTF-16 surrogate pair, the form JSON requires (the emoji U+1F600 becomes \uD83D\uDE00). JavaScript output can use \u{1F600} instead.
URLs work differently: the text is converted to UTF-8 bytes first and each byte is percent-encoded. HTML uses numeric references such as 😀. Example: é😀 is \u00E9\uD83D\uDE00 in JSON, %C3%A9%F0%9F%98%80 in a URL.
A lone surrogate (half of a pair) is not valid text. The tool writes it as an escape in JSON and JavaScript, and refuses to percent-encode it, since it has no UTF-8 form.
Contexts in detail
JSON string
Follows RFC 8259: escapes ", \ and control characters, and optionally every non-ASCII character and /. Unescape accepts the text with or without surrounding quotes and is strict: an invalid escape such as \q, an unescaped quote or a raw line break is reported with its line and column. To check a whole JSON document, use the JSON Validator; to tidy one, the JSON Formatter.
JavaScript string
Handles double, single and template-literal quotes, \xNN, \uNNNN, \u{...}, \0, \v and line continuations. In a template literal ${ is escaped too. U+2028 and U+2029 are always written as escapes. Unescape rejects legacy octal escapes such as \1.
Unicode escapes
Writes every non-ASCII and control character as \uXXXX and doubles backslashes so the result can be reversed. It does not escape quotes, so use JSON or JavaScript when the text goes inside a string literal. Unescape is lenient: unknown escapes are left as written.
HTML text and attributes
Escapes & < > " ' as & < > " ', which is correct for text content and quoted attribute values. Unescape decodes those, ', and numeric references; other named entities are left as written. The HTML Entity Encoder & Decoder covers the full list of names, and the HTML Formatter can tidy the surrounding markup.
URL (percent-encoding)
Three kinds, shown here for a&b=c d/é:
| Kind | Result | Use it for |
|---|---|---|
| Component | a%26b%3Dc%20d%2F%C3%A9 | A single query value or path segment. Encodes & = / ? #. |
| Full URL | a&b=c%20d/%C3%A9 | A whole URL that is already structured. Keeps : / ? # & =, so it will not protect a value that contains them. |
| Form | a%26b%3Dc+d%2F%C3%A9 | application/x-www-form-urlencoded bodies. A space becomes +. |
Unescape reports the position of a malformed % sequence. For splitting a URL into parts, see the URL Parser; for a dedicated encoder with more options, the URL Encoder & Decoder.
CSV field
Follows RFC 4180 for one field: it is wrapped in double quotes when it contains the delimiter, a double quote or a line break, and quotes inside are doubled (say "hi", ok becomes "say ""hi"", ok"). CSV does not use backslashes. Choose a comma, semicolon, tab or pipe as the delimiter. The tool treats the whole input as one field. It does not parse whole CSV files; use the CSV Viewer for that.
Regular expression
Escapes the characters that have a meaning in a pattern, \ ^ $ . * + ? ( ) [ ] { } |, so user text can be matched literally (1.5 (USD)+ becomes 1\.5 \(USD\)\+). Optional: / for regex literals and - (written \x2d) for character classes. It is written for JavaScript patterns; test the result in your own engine with the Regex Tester.
Shell argument
POSIX single quotes keep everything literal; an embedded single quote is written '\'', so it's here becomes 'it'\''s here'. The $'...' style writes line breaks and tabs as \n and \t and works in Bash and Zsh, not in plain POSIX sh (example: $'a\tb\nc'). This is not for Windows cmd.exe or PowerShell, and a NUL character cannot be passed in a shell argument. To build a full command, see the cURL Command Generator. Unescape reads one shell word only (single, double, $'..' and backslash quoting) and never runs or expands anything.
Escaping is not sanitizing
Escaping changes how characters are written so a parser reads them as data. Sanitizing removes or rewrites content you do not want. They solve different problems and neither replaces the other. This tool escapes only.
- Context decides safety. HTML escaping makes text safe as element content or as a quoted attribute value. It does not make it safe inside
<script>or<style>, in event-handler attributes such asonclick, in an unquoted attribute, or as the value ofhreforsrc, where ajavascript:URL is still a URL. - JSON inside a script tag. Valid JSON is not automatically safe in HTML. A string containing
</script>ends the script early. Escape/(and<as\u003C) when embedding untrusted data. - SQL is not covered. Do not build queries by escaping strings. Use parameterized queries or prepared statements.
- Shell. Quoting one argument is fine for a command you write by hand. In programs, pass arguments as a list (for example with
execFileorsubprocesswithout a shell) instead of assembling a command line. - CSV and spreadsheets. A quoted cell that starts with
=,+,-or@can still be run as a formula by a spreadsheet. Quoting does not prevent this. - Escape at the last step, once. Escape for the destination when you write the output, and unescape when you read it. Do not store escaped text and escape it again.
Common mistakes
- Double escaping. A sign of it is
\\nin the output or&on the page. The tool warns when an unescaped result still looks escaped. - Wrong context. Using a URL encoder for a JSON body, or
encodeURIfor a query value (it leaves&and=alone). - Pasting JSON with its quotes. Unescape removes one pair of surrounding quotes; Escape adds them only if you tick Add surrounding quotes.
- Treating
\/as special. It is valid JSON for a plain slash. It is only needed in some embedding cases. - Escaping text that is already a pattern. Regex escaping is for literal text. Do not run it on a pattern you want to keep working.
- CSV with backslashes. Standard CSV escapes a quote by doubling it, not with
\". - Base64 is not escaping. It re-encodes bytes into a limited alphabet. If you need that, use the Base64 Encoder & Decoder.
How to use it
- Choose Escape to prepare text for a context, or Unescape to read escaped text.
- Choose the context. Options that apply to it appear next to the menus.
- Paste your text. The output and the comparison table update as you type. Errors in unescape mode show the line and column of the problem.
- Copy the output, or use Swap to move it to the input and switch direction. The notes list anything to check.
Frequently asked questions
How do I escape a string for JSON?
Choose the JSON context and Escape. Quotes, backslashes and control characters are escaped; tick Add surrounding quotes if you want the result ready to paste as a value.
What is the difference between escaping and URL encoding?
URL encoding (percent-encoding) is the escaping rule for URLs. It is one of the contexts here, next to JSON, HTML and others, each with its own rules.
Does unescaping make text safe?
No. Unescaping only restores the original characters. Never put the result back into HTML, a query or a shell command without escaping for that destination.
Why does my output differ from another tool?
Options differ: whether quotes are added, whether non-ASCII characters are escaped, how / and characters above U+FFFF are written. Check the options for the context.
Privacy and local processing
This tool runs entirely in your browser. Your text is escaped by JavaScript on this page and is not sent to a server. Nothing is stored. Because strings often contain tokens or passwords, you can safely use it for them, but avoid pasting secrets into any page you do not trust.