FA Dev Tools

Escape JSON String

Escape a string so it can be embedded inside a JSON string value (quotes, backslashes and control characters are backslash-escaped), or unescape it back to the original text.

Instructions

Escapes text so it can live inside a JSON string value, or unescapes it back to the original.

  1. Paste the text into the input.
  2. Choose Escape (raw text → JSON-safe) or Unescape (JSON-safe → raw text).
  3. The output updates as you type; Copy takes the result.

Tips

  • Escaping covers ", \, newlines, tabs and every other control character, as RFC 8259 requires, so a Windows path like C:\Users becomes C:\\Users. Unescape reverses every JSON escape, including \uXXXX.
  • Common use: pasting a whole JSON document as the value of another JSON field, or reading a log line that arrived escaped.
  • Hit Example and pick a direction to load a sample already in the right shape.

About escaping JSON strings

Why JSON strings need escaping

A JSON string sits between two double quotes. Some characters cannot appear in it as they are. RFC 8259 (section 7) says a string must escape the double quote, the backslash and the control characters U+0000 to U+001F, which include newline and tab. The short escapes are \", \\, \/, \b, \f, \n, \r and \t. Any other character can be written as \u plus four hex digits.

You need this whenever text goes inside a JSON value by hand: a multi-line SQL query or shell script in a config file, a prompt in an API request, or a whole JSON document stored as a string field, which is common in message queues, webhooks and log pipelines.

What this tool changes

Escape does what RFC 8259 asks: each double quote becomes \", each backslash \\, line breaks and tabs \n, \r and \t, and any other control character a \u escape. The output matches what JSON.stringify puts between its quotes. It has no quotes around it, so paste it between the quotes of the value you are writing. For example, a line say "hi" followed by a second line becomes say \"hi\"\n plus the second line.

Unescape reverses every JSON escape, including \\, \/ and \u00e9, reading left to right so an escaped backslash followed by n stays a backslash and an n. It is handy for a log line or an API error that shows a payload full of backslashes. The output updates as you type, and everything runs in your browser.

Backslashes and Windows paths

Backslashes are the usual trap when escaping by hand. A Windows path such as C:\Users\derek must become C:\\Users\\derek: left single, a JSON parser rejects \U as an unknown escape, and a path like C:\new is silently read as a line break. This tool doubles them for you, and a Windows line break (CR LF) is kept as \r\n, so escaping and unescaping gives back exactly what you started with.

Double escaping

When a JSON string is escaped twice, quotes show up as \\\" and line breaks as \\n. This happens when a service stores a JSON document as a string and another layer escapes it again. Each layer needs one decode: press Unescape, copy the output back into the input, and unescape again until the quotes are plain. The same conversion is also available as JSON String Encode/Decode, laid out like the other encode and decode tools on this site.

Frequently asked questions

Which characters must be escaped in a JSON string?
The double quote, the backslash and the control characters U+0000 to U+001F (such as newline, carriage return and tab). The forward slash may be escaped but does not have to be. Non-ASCII text such as accents or Chinese can stay as it is in UTF-8.
Why are there backslashes before every quote in my log?
The JSON was stored as a string inside another JSON value, so its quotes were escaped. Unescape it once to get the inner document back. If you still see backslashes, it was escaped twice.
How do I escape a string for JSON in JavaScript?
Call JSON.stringify on the string. It adds the surrounding quotes and escapes quotes, backslashes and control characters. JSON.parse on that quoted string gives the original text back.