JSON Escaper
Prepare a raw string for a JSON value.
About this tool
The result is the escaped content, not a quoted JSON document.
It does not validate that the original text was JSON.
How to use it
- Open this page and provide the input it asks for.
- Set the options that are visible, then use Escape.
- Read the result in the panel. Copy it or download it when a file is offered. The input stays in this browser.
Limitations
- It does not validate that the original text was JSON.
Quotes sliced off a JSON string encoding
The paste becomes the interior of a JSON string
JSON.stringify wraps the paste, then the outer quotes are sliced off. The page takes whatever is in the box, including line breaks and quote marks, and encodes it the way a JSON string would encode those characters. The two quote characters that stringify places at the ends are removed, so the result is ready to drop between quotes in a larger JSON document. It is not itself a JSON document. Pasting the result into the JSON formatter will fail unless you add the quotes back.
Newlines become the two-character escape for a newline. A double quote becomes a backslash and a quote. Backslashes are doubled. Characters that JSON requires to be escaped are escaped. A slash is left as a slash, because the encoder does not add a needless escape for it. The text is not encrypted. Anyone who can read the escapes can reverse them with the unescaper or with a JSON parse of a quoted copy.
What this is not
The escaper does not check that the paste is already JSON. A paragraph of prose is a fine input. The output is the escaped form of that prose, not a pretty object. The formatter parses an object or array and reprints it. This page never parses the paste as a value. If you feed it an object that is already JSON text, the braces and quotes are ordinary characters and they get escaped too, which is correct for embedding that text inside another string and wrong if you thought the page would format the object.
Round trip with the unescaper
The unescaper is the inverse for this interior form. It also accepts a fully quoted JSON string. Keep the two pages straight when a value fails: an error on the unescaper often means the escapes are not a legal string encoding, while an error on the formatter means the text is not a JSON value. Use the escaper when a string must travel inside JSON. Use the formatter when the text is the JSON value itself.
Privacy
Your input is processed in your browser and is not uploaded to UtilChain. File names, text, and results are not sent to analytics.

