Text Escape/Unescape
Escape or unescape text for shell, regex, JSON, SQL, or XML contexts.
POST
1 credit
/v1/text-escape
curl -X POST "https://devtools.toolkitapi.io/v1/text-escape" \
-H "Content-Type: application/json" \
-d '{"text": "Hello \"world\" & <friends>", "context": "xml"}'
import httpx
resp = httpx.post(
"https://devtools.toolkitapi.io/v1/text-escape",
json={"text": "Hello \"world\" & <friends>", "context": "xml"},
)
print(resp.json())
const resp = await fetch("https://devtools.toolkitapi.io/v1/text-escape", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({"text": "Hello \"world\" & <friends>", "context": "xml"}),
});
const data = await resp.json();
console.log(data);
# See curl example
Response
200 OK
{
"context": "xml",
"mode": "escape",
"result": "Hello "world" & <friends>"
}
Try It Live
Live Demo
Response
Description
Escape or unescape text for shell, regex, JSON, SQL, or XML contexts.
How to Use
1
1. Send a POST request with `text`, `context`, and optionally `unescape: true` for the reverse operation.
2
2. The `result` field contains the escaped (or unescaped) text.
About This Tool
Text Escape/Unescape converts text to and from escaped representations for five common contexts: shell, regex, JSON, SQL, and XML. Use it to safely embed user input in queries, commands, or markup.
Why Use This Tool
- Security — Escape user input before embedding in SQL, shell commands, or XML
- Debugging — Unescape encoded strings to read their original values
- Code generation — Properly escape strings for different target languages
Frequently Asked Questions
What does each context do?
- **shell** — Wraps in single quotes (POSIX `shlex.quote`)
- **regex** — Escapes regex metacharacters (`re.escape`)
- **json** — Escapes for JSON string embedding (backslash sequences)
- **sql** — Doubles single quotes (`'` → `''`)
- **xml** — Converts `<`, `>`, `&`, `"`, `'` to XML entities
Does unescape work for all contexts?
Unescape works reliably for `json`, `xml`, and `sql`. Shell and regex unescaping is ambiguous, so the original text is returned as-is for those contexts.
Start using Text Escape/Unescape now
Get your free API key and make your first request in under a minute.