Skip to content
Accessibility
Theme
Text size
High contrast
Limit animations
Readable fontAtkinson Hyperlegible
Increased text spacing
Underline links
Always show focus

Runs in your browser — nothing you paste is uploaded.

Escape & Unescape

Escape a string for JSON, JavaScript, HTML or SQL — or reverse it. Runs in your browser.


    

What it does

Takes a raw string and makes it safe to paste inside a quoted literal — or reverses the process. Pick a format, type or paste on the left, and the escaped (or unescaped) result appears on the right ready to copy. Switching formats or toggling Unescape re-runs instantly; nothing is sent anywhere.

The four formats

  • JSON — escapes ", \ and control characters (\n, \t, \r and the rest) exactly as JSON.stringify would, then strips the surrounding quotes so you get just the string body.
  • JavaScript — the same as JSON but also escapes the single quote (' → \'), so the result drops cleanly into either a single- or double-quoted JS string.
  • HTML — replaces the reserved characters &, <, >, " and ' with entities so the text renders as-is instead of being parsed as markup. For bulk entity work on accented or non-ASCII text, see the dedicated HTML entity encoder.
  • SQL — doubles single quotes (' → '') so a value sits safely inside a single-quoted SQL literal.

Unescape

Tick Unescape to go the other way: JSON and JavaScript turn sequences like \n and \" back into real characters, HTML decodes named and numeric entities, and SQL collapses '' back to a single '.

Worked examples

The string He said "hi" followed by a newline becomes, in JSON mode, He said \"hi\"\n — paste that between quotes and it is a valid literal. In SQL mode the name O'Brien becomes O''Brien, so INSERT ... VALUES ('O''Brien') stores the apostrophe correctly.

Common gotchas

  • SQL mode is a formatting helper, not an injection defence — use parameterised queries for untrusted input.
  • When unescaping, paste the string body only, without the outer quotes, or JSON parsing will fail.
  • HTML escaping here covers the five reserved characters; it won't convert accented letters to entities (that's what the non-ASCII option on the HTML entity tool is for).

When to use it

Reach for it when hand-editing a config or source file — embedding a snippet of HTML or a path inside a JSON value, pasting a quote-heavy sentence into a JS string, or dropping an apostrophe-laden name into a one-off SQL statement. For encoding values into URLs use the URL encoder, and for binary-safe text use Base64.

Privacy

All processing is local; nothing is uploaded.

Frequently asked questions

What's the difference between JSON and JavaScript escaping?

Both escape double quotes, backslashes and control characters such as newline and tab. JavaScript mode additionally escapes the single quote (' → \'), because a JS string can be wrapped in single quotes whereas a JSON string is always double-quoted. When you don't know which quote style the target code uses, JavaScript mode is the safe choice.

Does SQL escaping protect against SQL injection?

No. This tool only doubles single quotes (' → '') so a value fits inside a single-quoted literal. It is a formatting convenience, not a security measure, and it doesn't know your database's dialect. For anything touching user input use parameterised queries or prepared statements — the only reliable defence against injection.

Why does unescaping JSON sometimes show an error?

Unescape parses your input as the inside of a JSON string, so it must be a valid escape sequence. A lone backslash, an unfinished \u escape (fewer than four hex digits), or a raw unescaped quote will throw. Paste the escaped body only, without the surrounding quotes, and make sure every backslash begins a complete sequence.

Related tools