Skip to the tool
GigaJSON

JSON Escape and Unescape

All tools
Format and check
View and query
Convert
JSON to code
Encode and decode
Sample files
Guides Open GigaJSON

Turn any text into a valid JSON string, with quotes, backslashes, line breaks and control characters escaped, the same as JSON.stringify. Paste JSON to stringify it: it's compacted first (strings and numbers stay exactly as written) and comes out as one string you can put in code, a test, an environment variable or another JSON document. Or go the other way: unescape a JSON string back into plain text. When the string holds JSON, such as {\"id\":1} from a log line, it comes back indented and coloured.

How to use it

  1. Choose Escape or Unescape.
  2. Paste the text, the JSON to stringify, or the JSON string to unescape.
  3. Copy the result. For JSON you can untick "Compact JSON first" to keep its line breaks.

Read more: Unescape JSON: fix strings full of backslashes

Private, local processing

This tool runs in your browser: nothing you paste is uploaded, and nothing is kept after you leave. Already loaded features keep working if your connection drops. Loading another tool or jq for the first time needs a connection. When one tool isn't enough, GigaJSON opens your data with a tree, a table, JSONPath/JMESPath/jq queries, transforms, diff and history.

What JSON escapes

Inside a JSON string, these characters can't appear as they are. This is what the tool (and JSON.stringify) writes for each:

CharacterEscaped
Double quote\"
Backslash\\
Line break (LF)\n
Carriage return (CR)\r
Tab\t
Backspace, form feed\b, \f
Other control characters (U+0000 to U+001F)\u0001 and so on
/, é, emoji and other UnicodeUnchanged

To put JSON inside JSON, escape it: {"id":1} becomes "{\"id\":1}". That's how a JSON payload ends up in a log line, a message queue or an environment variable. Unescape reverses it.

Stringify JSON in code

The same result as this page, in JavaScript and Python:

LanguageCodeResult for {"id": 1}
JavaScript, JSON textJSON.stringify(obj){"id":1}
JavaScript, as a stringJSON.stringify(JSON.stringify(obj))"{\"id\":1}"
Python, JSON textjson.dumps(obj){"id": 1}, with spaces
Python, as a compact stringjson.dumps(json.dumps(obj, separators=(",", ":")))"{\"id\":1}"

Parsing a number in code can round it: 12345678901234567890 becomes 12345678901234567000 in JavaScript. This page never parses your numbers, so they stay as you pasted them.

Questions

How do I stringify JSON online?

Paste the JSON with Escape selected. It is compacted to one line and escaped, so {"id": 1} becomes "{\"id\":1}". Untick "Compact JSON first" to keep the indentation, written as \n.

What is the difference between JSON.stringify and escaping?

JSON.stringify(obj) turns an object into JSON text: {"id":1}. Escaping turns text into a JSON string literal, quotes and all. Stringifying JSON so it fits inside a string is both: JSON.stringify(JSON.stringify(obj)), which gives "{\"id\":1}". That is what this page does with JSON input.

What gets escaped?

Double quotes, backslashes, line breaks, tabs and other control characters. It's the same as what JSON.stringify does.

How do I unescape JSON that is inside a string?

Switch to Unescape and paste the string, quotes included, such as "{\"id\":1}". The result is the JSON, indented. Numbers with 16 or more digits are left exactly as written instead of being reformatted, so no digits are lost.

Does / need to be escaped in JSON?

No. JSON allows \/ but doesn't require it, so this tool leaves / as it is. Both forms read back the same.

How do I escape a string in JavaScript or Python?

JavaScript: JSON.stringify(text). Python: json.dumps(text), which also turns every non-ASCII character into \u escapes (é becomes \u00e9) unless you pass ensure_ascii=False. This tool keeps é as it is, like JSON.stringify.

Why does my JSON show \n instead of line breaks?

The text was escaped twice: a JSON string was stored inside another JSON string. Unescape it once here to get the inner text back.

Unescape says the input is invalid

Unescape expects one JSON string, with or without the quotes around it, e.g. "line one\nline two".

All tools