JSON string escape and unescape

Escape text for a JSON, JavaScript, SQL, shell, CSV, XML or regex string, or unescape it.

Runs in your browser. Your input is not uploaded.

What it does

Every string syntax has characters that end the string or start an escape. Escaping writes those characters so the string survives: a quote inside a JSON string becomes \", a new line becomes \n.

Each format has its own rules. JSON, JavaScript, SQL, POSIX shell, CSV, XML and regular expressions are covered.

How to use it

  1. Choose the format.
  2. Paste the raw text to escape it, or the escaped text to unescape it.
  3. Copy the result, ready to place between the quotes.

Example: JSON

Input
He said "hi"
then left
Output
He said \"hi\"\nthen left

Things to watch for

  • SQL escaping is not a substitute for parameterised queries. Use it for one-off scripts, not application code.
  • The shell format wraps the value in single quotes. That is the only quoting that disables every expansion.
  • JSON requires double quotes; single-quoted strings are not valid JSON.

Questions

How do I escape a string for JSON?
Choose JSON. Quotes, backslashes and control characters are escaped exactly as JSON.stringify does, without the surrounding quotes.
How do I unescape \n into real new lines?
Choose JSON or JavaScript and Unescape. \n, \t, \uXXXX and the rest become the characters they stand for.
How do I escape a single quote in SQL?
Double it: O'Brien becomes 'O''Brien'.
How do I put a string in a regex literally?
Choose Regex. Every special character is backslash-escaped so the pattern matches the text exactly.