String Escape / Unescape - JSON, JS, Java, CSV, SQL
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
| Mode | Escapes | Example output |
|---|---|---|
| JSON | \" \\ \n \r \t \b \f, other control characters as \u00XX | He said \"hi\"\n |
| JavaScript | As JSON, plus \' and \` | it\'s \`ok\` |
| Java / C | \\ \" \n \r \t \b \f, other control characters as octal \NNN | C:\\temp\\new |
| CSV | Wrap in "...", double any " inside | "Smith, ""Jo""" |
| SQL | Double each single quote | O''Brien |
| Regex | Backslash 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:\newcontains a newline escape. Escape it toC:\\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
JWT Decoder
Decode JSON Web Tokens and inspect header, payload and signature.
Base64 Encode / Decode
Encode text to Base64 or decode Base64 strings back to plain text.
URL Encode / Decode
Percent-encode or decode URLs and query-string parameters safely.
Hash Generator
Generate MD5, SHA-1, SHA-256, SHA-384, and SHA-512 hashes from text.