String escaper — escape or unescape text for JSON, JS, HTML, SQL, regex and shell

Paste text, choose where it is going (a JSON string, a JavaScript string, HTML, XML, an SQL literal, a regular expression, a POSIX shell argument, a CSV field or a URL component) and the tool escapes it for that context, or reverses the escaping.

Live demo · real result from this tool
Mode

Escaped

He said \"it's <b>done</b>\" & left\nPath: C:\\temp

Processed on your device — nothing is uploaded.

How to use the string escaper

  1. Paste or type into Text. Line breaks and tabs count.
  2. Choose the Context: JSON string, JavaScript string, HTML, XML, SQL string literal, Regular expression, Shell (POSIX single quotes), CSV field or URL component.
  3. Choose Mode: Escape to make the text safe for that context, or Unescape to turn an escaped value back into plain text.
  4. Copy the result. JSON and JavaScript results come without the outer quotes; SQL, shell and CSV results include them where the rules need them.

What it does and when to use it

Every language has characters that end a string early or change its meaning: a quote in JSON, a $ in a regex, a ' in SQL or shell, a < in HTML. Escaping them by hand is slow and error-prone. This tool handles the rule set for the target you pick. Use it to put a Windows path or a multi-line message into a JSON config, build a regex that matches a literal price, add a name such as O’Neil to an SQL seed file, or pass a message with spaces and quotes to a shell script.

Related tools cover single jobs in more depth: JSON String Escape for JSON only, the JS Regex Escaper for patterns, and the HTML Entities Ref to look up an entity name.

How it works

Context Escape rule
JSON " and \ get a backslash; control characters become \n, \t or \uXXXX (RFC 8259)
JavaScript backslash escapes for a single-quoted ECMAScript string
HTML / XML & < > " ' become entities (&#39; in HTML, &apos; in XML)
SQL ' doubled, whole value wrapped in '…'
Regex \ ^ $ . * + ? ( ) [ ] { } | / - get a backslash
Shell wrapped in '…', each ' becomes '\''
CSV quoted and " doubled when the field has , " a line break or edge spaces (RFC 4180)
URL encodeURIComponent; unescape also reads + as a space

Everything runs in your browser.

Worked examples

A literal price in a regex. Text price: $9.99 (USD)?, context Regular expression:

price: \$9\.99 \(USD\)\?

A JavaScript string. Text with a line break, a tab and double quotes gives Line 1\nTab\there "quoted", ready to paste between single quotes.

An SQL literal. O'Neil becomes 'O''Neil'.

A URL component. a&b=c d/é becomes a%26b%3Dc%20d%2F%C3%A9. A broken escape such as 100% in Unescape mode returns an error instead of a guess.

Limits and tips

  • Pick the context of the innermost layer first. A JSON value inside a shell command needs JSON escaping, then shell escaping.
  • To build a whole query string at once, use the Query String Builder.

Frequently asked questions

Is SQL escaping enough to stop SQL injection?
No. Use parameterised queries or your driver's placeholders for any value that comes from users. The SQL mode doubles single quotes as standard SQL does, which is fine for a one-off script or test data, but MySQL with backslash escapes enabled reads some inputs differently.
Why does the JavaScript mode leave double quotes alone?
It escapes for a string in single quotes, so only ' and backslashes, line breaks and other control characters need escaping. Paste the result between '…'.
Does HTML escaping make text safe everywhere in a page?
It is safe for text between tags and for attribute values in quotes. It is not enough inside script blocks, style blocks, or URL attributes such as href with a javascript scheme.
Which shell does the Shell mode target?
POSIX shells such as sh, bash and zsh. The text is wrapped in single quotes and each ' becomes '\''. Windows cmd and PowerShell quote differently.
Does unescaping HTML know every named entity?
It decodes all numeric references and the 260 named entities in the HTML Entities Ref, which covers the common ones. Rare names outside that list are left as they are.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close