UtilToolkits2025-12-19
TL;DR — The String Escaper escapes (and unescapes) text for JSON, HTML, JavaScript, SQL, Java, Python, and shell — one tool, no mental gymnastics. Pair with the JSON Formatter to verify your escaped string parses, and the HTML Entity Encoder for the entity-name variant.
Every text-based format has reserved characters with structural meaning: " ends a JSON string, < starts an HTML tag, ' ends a SQL string literal. To include those characters as literal data, you replace them with an escape sequence the parser understands as "treat this as content, not syntax."
| Format | Must escape | How |
|---|---|---|
| JSON | " \ / + control chars | Backslash: \" \\ \n \t \uXXXX |
| HTML | < > & " ' | Entities: < > & " |
| JavaScript | ' " ` \ + newlines | Backslash escapes; or use template literals |
| SQL | ' | Double up: ' → '' (or use parameterized queries) |
| Shell (Bash) | ' " $ ` \ ! * | Single-quote whole string, or backslash-escape |
| URL | Almost everything | Percent-encode (see the URL Encoder) |
// Raw query
SELECT * FROM users WHERE name = 'O\'Brien'
// Escaped for a JS string
"SELECT * FROM users WHERE name = 'O\\'Brien'"
Escaping is the cheap way. The right way is to use the API for your context: parameterized queries for SQL (? or $1 placeholders), template engines for HTML (which auto-escape), and execFile with array args instead of exec for shell. Escaping is what you reach for when those aren’t available, and what you double-check with the String Escaper when they are.
Technically yes if done perfectly. Practically no — humans miss edge cases. Use parameterized queries; reserve escaping for truly dynamic SQL that can’t be parameterized.
Before displaying, in the format of the target context. Storing raw is usually correct — you don’t know yet whether it’ll be rendered as HTML, JSON, or plain text.
Mostly the same idea in different formats. "Escaping" usually refers to source-code contexts (JSON, JS, SQL). "Encoding" usually refers to transport (URL, Base64, HTML entities).