JSON Escape and Unescape Online

Escape text or a JSON document into a JSON string, or unescape (unstringify) a JSON string back to readable text or JSON. Runs in your browser — nothing is uploaded.

What JSON escaping does

A JSON string is text between double quotes, and a few characters cannot appear inside it literally. JSON escaping rewrites them with a backslash so the value survives being embedded in a JSON document, a log line, an environment variable or source code:

CharacterEscapedCharacterEscaped
double quote "\"backslash \\\
newline (LF)\ncarriage return (CR)\r
tab\tbackspace / form feed\b / \f
other control chars U+0000–U+001F\u00XXnon-ASCII (optional)\u00E9, \uD83D\uDE00

The forward slash may be written \/ but never has to be; this tool leaves it alone, as JSON.stringify does.

Escape: JSONify a string or encode JSON

The Escape / Stringify tab runs the input through JSON.stringify. With Wrap in quotes on you get a complete JSON string literal — this is what “JSONify string” means: a two-line note becomes "line one\nline two", ready to drop into a JSON file or API request body. Turn it off to get just the escaped inner text for pasting between quotes you already have.

Tick Minify JSON first to JSON encode a document: if the input is valid JSON it is minified and then encoded as a string, so {"a": "b"} becomes "{\"a\":\"b\"}". Text that is not JSON is encoded as a plain string, and the status line says which happened. Escape non-ASCII writes every character above U+007F as \uXXXX for ASCII-only transports.

Unescape: unstringify and decode nested JSON

The Unescape / Parse tab reverses the process with JSON.parse. Paste "{\"a\":1}" and you get back {"a":1}; paste text without the surrounding quotes, such as line one\nline two, and it is treated as the inside of a string. This is how to read JSON that was stored as an escaped string inside a log, a database column or another JSON document.

Multiline JSON

The Multiline JSON tab parses JSON (unwrapping a stringified value if needed) and re-serialises it with one property per line, indented by 2 spaces, 4 spaces or a tab — handy when a compact API response has to be readable in a pull request or documentation page. Invalid JSON is reported with the parser’s error message. If you actually need a multiline string inside JSON, use Escape: raw line breaks are not allowed in JSON strings, so each becomes \n.

Worked example

Input text:     She said "hi"
                C:\temp
Escaped:        "She said \"hi\"\nC:\\temp"
Encoded JSON:   {"id": 7}  ->  "{\"id\":7}"
Unstringified:  "{\"id\":7}"  ->  {"id": 7}

Escaping JSON in code

// JavaScript
JSON.stringify('She said "hi"\n');           // '"She said \\"hi\\"\\n"'
JSON.parse('"She said \\"hi\\"\\n"');        // 'She said "hi"\n'
JSON.stringify(JSON.stringify({ id: 7 }));   // '"{\\"id\\":7}"'  (JSON encode)

# Python
import json
json.dumps('She said "hi"\n')                # '"She said \\"hi\\"\\n"'
json.loads(json.loads(double_encoded))     # decode two levels

Common questions

Which characters have to be escaped in a JSON string?

The double quote (as \"), the backslash (as \\) and every control character below U+0020. Newline, carriage return, tab, backspace and form feed have short forms (\n, \r, \t, \b, \f); the rest use \u00XX. Everything else, including non-ASCII letters and emoji, may appear as is.

How do I unstringify JSON?

Choose Unescape and paste the string, for example "{\"a\":1}" copied from a log. It is parsed as a JSON string literal and the text inside is shown. Turn on Decode nested levels and Pretty-print to get readable, indented JSON even if the value was stringified two or three times.

What is the difference between JSON escape and JSON encode?

Escaping treats the input as plain text and wraps it in a JSON string literal. JSON encode (Minify JSON first) checks whether the input is valid JSON, minifies it, and then escapes it, which gives the compact string you embed in another JSON field or an environment variable.

How do I put a multiline string in JSON?

JSON strings cannot contain raw line breaks. Paste the multiline text and choose Escape: each line break becomes \n inside one quoted string. To go the other way, and turn compact JSON into readable multiline JSON, use the Multiline JSON tab.

Is JSON escaping the same as URL encoding or HTML escaping?

No. JSON escaping only makes text safe inside a JSON string literal. A JSON value placed in a URL still needs percent-encoding (URL encoder), and one placed in HTML still needs HTML entity escaping (HTML escape).

Is my data uploaded?

No. Escaping and unescaping use the browser’s own JSON.stringify and JSON.parse. Nothing leaves the page.