String Escaper

Escape or unescape strings for JSON, URLs, HTML, SQL literals, and regular expressions. One tool, five languages, zero upload.

Escape or unescape a string for five contexts with each context’s exact rules: JSON string literals, URL components, HTML entities, SQL single-quote literals, and regular-expression metacharacters. No guessing, no mode bleed — pick the language, get the honest transformation.

How to use String Escaper

  1. Pick the context and paste the raw text.
  2. Press Escape or Unescape depending on the direction.
  3. Copy the result into your code, query, or markup.

Who it is for

Developers embedding user text into generated code, support engineers quoting values for tickets and queries, students learning why each language escapes differently, and QA teams testing injection handling.

How it works

  • JSON mode emits the full quoted literal with real \" and \n escapes and parses it back on unescape, so round-trips are guaranteed.
  • URL mode uses strict component encoding (every reserved character), HTML mode covers the five dangerous entities, and regex mode escapes exactly the metacharacter set.
  • SQL mode doubles single quotes — with an explicit note that parameterised queries remain the only real defence.

What it cannot do

  • Five contexts only — shell, CSV, and JSONPath escaping are different rulesets.
  • SQL quoting protects literals, not structure; it cannot make a concatenated query safe.

Sample input & output

You give

Context: JSON | Raw string: Line 1: "Hello"\path Line 2: $25 & <ok>

String Escaper returns

"Line 1: \"Hello\"\\path\nLine 2: $25 & <ok>" — valid RFC 8259 JSON string literal ready to paste or unescape losslessly.

Frequently asked questions

Why does JSON mode wrap my text in quotes?

A JSON string literal includes its quotes — the tool emits the complete literal so you can paste it straight into a payload.

Does SQL escaping make my query safe from injection?

No. It makes a literal correct. Real safety comes from parameterised queries; use this for reports and quick checks only.

Why do HTML entities cover only five characters?

& < > " and the apostrophe are exactly the characters with special meaning in text content and attributes — the rest pass through as-is.

Which characters MUST be escaped inside a valid RFC 8259 JSON string?

RFC 8259 Section 7 mandates escaping double quotation marks (\"), reverse solidus backslashes (\\), and all 32 ASCII control characters from U+0000 through U+001F — either via shorthand escapes (\b, \f, \n, \r, \t) or six-character Unicode escapes (\u00XX). Literal newlines or unescaped tabs inside JSON strings are syntax errors in every spec-compliant parser.

Why does HTML entity mode escape &, <, >, ", and ' specifically?

Those five characters control HTML state transitions under the WHATWG HTML parsing specification: '<' and '>' open or close tags, '&' starts character references, and '"' or "'" terminates double- or single-quoted attribute values (such as title='...'). Escaping all five (&amp;, &lt;, &gt;, &quot;, &#39;) neutralizes markup injection in element text and quoted attributes alike (though never inside unquoted attributes or <script> blocks).

Which metacharacters are escaped in Regular Expression mode?

ECMAScript RegExp syntax assigns special meaning to .*+?^${}()|[\]\\ (and '/' inside regex literals). Escaping each metacharacter with a leading backslash lets you safely interpolate arbitrary user search terms — such as "C++ (x86)" or "$19.99?" — inside new RegExp(escapedPattern, 'gi') without throwing unterminated-group errors or matching wildcards unintentionally.

Why is doubling single quotes (' -> '') insufficient to stop SQL injection in production code?

Standard ANSI SQL escapes a literal single quote inside 'string' literals by doubling it ('O''Reilly'). However, SQL escaping fails if the value is interpolated into an unquoted numeric column, an identifier, a LIKE wildcard clause, or a legacy MySQL connection using NO_BACKSLASH_ESCAPES=OFF or multibyte GBK encodings. Use this mode only for static seed migrations, and always bind parameterized prepared statements at runtime.