Skip to content

String Escape / Unescape - JSON, JS, Java, CSV, SQL

Raw text
Escaped JSON

Escape and Unescape Strings for Code

Every language has characters that cannot appear raw inside a string literal. A double quote ends a JSON string, a newline breaks a Java literal, and a comma splits a CSV field. This tool applies the right rules for six common formats. Pick a tab, choose Escape or Unescape, and paste your text. The result updates as you type.

What Each Mode Changes

ModeEscapesExample output
JSON\" \\ \n \r \t \b \f, other control characters as \u00XXHe said \"hi\"\n
JavaScriptAs JSON, plus \' and \`it\'s \`ok\`
Java / C\\ \" \n \r \t \b \f, other control characters as octal \NNNC:\\temp\\new
CSVWrap in "...", double any " inside"Smith, ""Jo"""
SQLDouble each single quoteO''Brien
RegexBackslash before . * + ? ^ $ { } ( ) | [ ] \ /1\.5\*2

Worked Example: Unescape a JSON String

Log lines and message queues often store JSON inside a JSON string, so you see something like this:

"{\"user\":\"ana\",\"tags\":[\"a\",\"b\"]}"

Paste it into the JSON tab with Unescape selected. The outer quotes are removed and each \" becomes a plain ":

{"user":"ana","tags":["a","b"]}

Other sequences are decoded the same way: \n becomes a line break, \t a tab and \u00e9 the letter é.

The result is ordinary JSON that you can format in the JSON formatter. Going the other way, Escape gives the same output as JSON.stringify without the outer quotes.

Double-Escaped Strings

If the result of Unescape still contains \" or \n, the value was escaped twice, usually because something called JSON.stringify on a string that was already JSON. Run Unescape again on the output. Each pass removes one layer. In JSON mode, unescaping rejects sequences JSON does not allow, such as \x41 or \'; those are JavaScript escapes, so switch to the JavaScript tab to decode them.

Tips for Each Format

  • JSON and JavaScript. Non-ASCII characters such as é or emoji are valid inside strings and are left as they are. Only quotes, backslashes and control characters need escaping.
  • Java and C. Windows paths are the classic trap: C:\new contains a newline escape. Escape it to C:\\new.
  • CSV. Escape one field at a time. To convert whole files, use the CSV to JSON converter.
  • SQL. Prefer query parameters in application code. Hand escaping is for quick manual queries.
  • Regex. Escaping makes text match literally, which is what you want when building a pattern from user input. Test the result in the regex tester.

For HTML, use the HTML entity encoder, and for URLs, use the URL encoder; both have their own rules.

Related Tools

Frequently Asked Questions

How do I unescape a JSON string?
Choose the JSON tab, select Unescape and paste the string, with or without its surrounding double quotes. Sequences such as \n, \" and \u00e9 are turned back into real characters. This is handy for logs and API responses that contain JSON stored inside a JSON string.
Is JSON escaping the same as JSON.stringify?
Yes. The JSON mode gives exactly what JSON.stringify produces for a string, minus the outer quotes, so you can paste it between quotes in a JSON file. Unescape is the same as JSON.parse on a quoted string.
What is the difference between the JavaScript and Java / C modes?
JavaScript mode also escapes single quotes and backticks, so the result is safe inside '...', "..." or `...` literals, and it understands \x, \u and \u{...} escapes when unescaping. Java / C mode escapes backslashes, double quotes and control characters, writing rare control characters as three-digit octal escapes that both languages accept.
Should I escape SQL strings by hand?
Only for one-off queries you run yourself. In application code, use parameterised queries or prepared statements so the database driver handles values safely. Doubling single quotes alone does not protect against every SQL injection, especially with unusual character sets or LIKE patterns.
Why does CSV escaping add quotes around my text?
RFC 4180 says a field containing a comma, double quote or line break must be wrapped in double quotes, and any double quote inside it is written twice. The tool also quotes fields that start or end with a space, because Excel and some parsers trim unquoted whitespace. Other fields are left unchanged.