What is string escaping?
String escaping replaces characters that have a special meaning in a format with a safe form. A quote in JSON becomes \", and < in HTML becomes <. You escape a string so that the format reads it as data. If you pick the wrong format, the string can break the code or open an injection hole.
How to escape a string
- Pick Escape or Unescape.
- Select the Format: JSON, XML, HTML, SQL or URL.
- Type or paste your string. The result updates as you type.
- Click Sample for an example in the selected format.
- Click Swap to send the result back to the input.
Which format do I pick?
Pick the place where the string will go. A value inside a JSON payload needs JSON. Text inside an HTML page needs HTML, and an XML attribute needs XML. A query parameter needs URL. Use SQL only to read or build literals during development. In production code, use parameterized queries.
Frequently Asked Questions
Which format should I pick?
The format of the place where the string goes: JSON for a JSON payload, HTML for a web page, XML for an XML file, SQL for a SQL literal, URL for a query parameter.
What is the difference between JSON and HTML escaping?
JSON escaping uses backslashes (\", \n) to protect the JSON syntax. HTML escaping uses entities (<, &) so that the browser does not read the text as markup. JSON-escaped text inside HTML is still open to XSS.
Is SQL escaping enough to stop SQL injection?
No. Escaping quotes covers common cases, but databases differ in encoding, comments and NULL bytes. Parameterized queries (prepared statements) are the reliable defense.
Why is the JSON result on one line?
JSON escaping gives the contents of a JSON string: a line break becomes \n and a tab becomes \t. Put the result between double quotes to get a full JSON string.
Does this tool send my data to a server?
No. Escaping and unescaping run in your browser. Your text stays on your device.