Free tool

String and JSON escape / unescape

Escape text so it fits inside a JSON string, a JavaScript literal, HTML, XML, SQL, a CSV field, a regex, a shell command or a URL, or unescape it back. Pick the format, paste your text, and the result updates as you type. Invalid escapes are pointed out with their line and column.

Free · no sign-up · runs in your browser, nothing is uploaded

String value inside JSON: \" \\ \n \t \uXXXX (RFC 8259).

Text
Escaped (JSON)

The escaped string appears here as you type.

What gets escaped in each format

Every format has a few characters that would end the string or change its meaning. Escaping replaces just those, so the parser reads them as plain text.

FormatCharactersWritten as
JSON" \ and U+0000-U+001F\" \\ \n \r \t \b \f \u00XX
JavaScriptthe quote you use, \, line breaks\' \" \` \\ \n \x41 \u00e9 \u{1F600}
HTML& < > " '&amp; &lt; &gt; &quot; &#39;
XML& < > " '&amp; &lt; &gt; &quot; &apos;
SQL''' (MySQL also \')
CSVdelimiter, " and line breaks"wrap the field" and "" for "
Regex. * + ? ^ $ { } ( ) | [ ] \\. \* \( …
Shelleverything; ' cannot be escaped inside '…''…' and '\'' for a quote
URLall but A-Z a-z 0-9 - _ . ! ~ * ' ( )%20 %26 %C3%A9 (UTF-8 bytes)

Escaping is not the same as encoding. Escaping keeps the text readable and only marks the dangerous characters; encodings like Base64 turn all of it into a different alphabet. For URLs specifically, the URL decoder also handles + as a space and double-encoded links.

JSON escape rules

RFC 8259 requires a backslash before " and \, and an escape for the 32 control characters U+0000 to U+001F. Eight short forms exist: \" \\ \/ \b \f \n \r \t. Anything else can be written as \uXXXX with four hex digits. A character outside the Basic Multilingual Plane, like most emoji, takes two of them (a UTF-16 surrogate pair): 😀 is \ud83d\ude00.

JSON has no \', \x41 or \u{1F600}. Those are JavaScript escapes, and a strict JSON parser rejects them. The tool flags them when you unescape.

// JavaScript
JSON.stringify('He said "hi"\n')   // '"He said \\"hi\\"\\n"'
JSON.parse('"caf\\u00e9"')          // 'café'

# Python
json.dumps('He said "hi"\n')       # '"He said \\"hi\\"\\n"'
json.dumps('café', ensure_ascii=False)  # keep non-ASCII as is

// Go
b, _ := json.Marshal("He said \"hi\"")

HTML and XML entities

In HTML text, only & and < must be escaped; inside an attribute value, & and the quote character that wraps the value. Escaping all five (& < > " ') everywhere is the simple, safe habit, and it is what template engines do. On a UTF-8 page you do not need entities for accented letters or emoji; the Other characters option writes them as named, decimal or hex references if your pipeline needs pure ASCII.

XML predefines only &lt; &gt; &amp; &apos; &quot;. Numeric references work for any allowed character, but control characters other than tab, line feed and carriage return are not allowed in XML 1.0 at all, not even as &#1;. The tool warns when your text contains one.

When you unescape HTML, numeric references from 128 to 159 are read the way browsers read them, as Windows-1252 (&#150; is an en dash, not a control character), and named entities beyond the HTML 4 set are resolved by your browser's own parser.

SQL, CSV and shell quoting

SQL. The standard way is to double the quote: 'O''Brien'. PostgreSQL, SQLite, SQL Server and Oracle work that way. MySQL and MariaDB also read backslash escapes (\' \n \\) unless NO_BACKSLASH_ESCAPES is on; PostgreSQL only does inside E'…' strings. Escaping is for building SQL by hand, like a migration or a one-off query. For user input, use placeholders.

-- one quote doubled
INSERT INTO people (name) VALUES ('O''Brien');

// Node (pg): the driver handles quoting
await client.query('INSERT INTO people (name) VALUES ($1)', ["O'Brien"]);

CSV. RFC 4180 wraps a field in double quotes when it contains the delimiter, a quote or a line break, and doubles any quote inside: "Smith, John ""Johnny""". The tool also quotes fields with leading or trailing spaces, which some spreadsheet apps trim. To convert whole files, use JSON to CSV.

Shell. Inside single quotes nothing is special, so a single quote cannot be escaped there: close the quote, add \', and reopen. Inside double quotes, $, `, " and \ still need a backslash. Bash and zsh's $'…' form reads C-style escapes like \n and \t.

echo 'it'\''s here'          # it's here
printf '%q\n' "it's here"     # bash: it\'s\ here
python3 -c 'import shlex; print(shlex.quote("it'"'"'s here"))'   # 'it'"'"'s here'

Regex and JavaScript strings

To match text literally in a regular expression, escape the 15 metacharacters . * + ? ^ $ { } ( ) | [ ] \. Add / when the pattern goes inside a /…/ literal. Newer JavaScript engines ship RegExp.escape(), which escapes more characters so the result is also safe inside character classes.

const escapeRegExp = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
new RegExp(escapeRegExp('$5.00 (approx)')).test('costs $5.00 (approx)')  // true

re.escape('$5.00 (approx)')     # Python
regexp.QuoteMeta("$5.00")       // Go

A JavaScript string escapes only the quote character that delimits it, the backslash and line breaks. In template literals, ` and ${ also need a backslash. Old octal escapes like \101 are a SyntaxError in strict mode and in template literals; the unescaper reads them but warns.

When you need to escape strings

  • Putting a code sample, an error message or a whole JSON document inside a JSON field (an API payload, a webhook test, a config value).
  • Reading a log line where JSON was serialized twice and every quote shows up as \".
  • Showing user text or code in HTML without the browser treating it as markup (XSS starts here).
  • Writing a seed file or migration with names like O'Brien.
  • Passing a filename with spaces or quotes to a command in a script or a CI step.
  • Searching for a literal string like $5.00 or a.b[0] with a regex tool.

To see the code points and bytes behind a strange character, use the Unicode converter. To check a JSON document after escaping, use the JSON formatter. Building an API? Browse API tools on DevHunt.

FAQ

How do I escape a string for JSON?+

Put a backslash before every double quote and backslash, and write control characters as \n, \r, \t, \b, \f or \u00XX. Everything else, emoji included, can stay as it is. Pick JSON above and paste your text, or in code use JSON.stringify(text) in JavaScript or json.dumps(text) in Python, which add the surrounding quotes too.

How do I unescape a JSON string?+

Switch the tool to Unescape and paste the string, with or without its outer quotes. In code, JSON.parse('"' + s + '"') in JavaScript or json.loads in Python does it. If the result still contains \" or \n, the text was escaped twice (common when JSON is stored inside another JSON string or a log line); the tool offers to unescape again.

Which characters must be escaped in JSON?+

Only three kinds, per RFC 8259: the double quote ("), the backslash (\), and the control characters U+0000 to U+001F. A forward slash may be written as \/ but does not have to be. Non-ASCII characters can be written directly in UTF-8 or as \uXXXX escapes.

How do I escape a single quote in SQL?+

Double it: 'O''Brien' is the string O'Brien in every SQL database. MySQL and MariaDB also accept a backslash ('O\'Brien') unless NO_BACKSLASH_ESCAPES is set. For values that come from users, use parameterized queries instead of escaping by hand.

What is the difference between escaping for HTML and for XML?+

Both use &amp; &lt; &gt; &quot; for the same characters. XML defines only five named entities (those four plus &apos;), so &nbsp; or &eacute; fail in XML unless a DTD declares them. HTML has more than 2,000 named entities. For a single quote, &#39; works in both.

How do I put a single quote inside a single-quoted shell string?+

You can't directly: nothing is special inside '…', not even a backslash. Close the quote, add an escaped quote, and reopen: 'it'\''s'. Bash and zsh also accept $'it\'s'. The Shell mode above does this for you.

How do I escape special characters in a regular expression?+

Put a backslash before . * + ? ^ $ { } ( ) | [ ] and \. In JavaScript, text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") does it, and newer engines have RegExp.escape(). Python has re.escape() and Go has regexp.QuoteMeta().

Is my text sent anywhere?+

No. Escaping and unescaping run in your browser with JavaScript. Nothing you paste is uploaded. Short inputs (up to 2,000 characters) are kept in the page address so you can bookmark or share the result, so do not paste secrets you would not put in a URL.

Sources: RFC 8259 (JSON), section 7 · MDN: string escape sequences · HTML Standard: character references · XML 1.0: predefined entities · MySQL: string literals · PostgreSQL: string constants · RFC 4180 (CSV) · MDN: RegExp.escape() · POSIX shell: quoting · Bash: ANSI-C quoting · MDN: encodeURIComponent(). Checked 2026-10-30.