Skip to content
Sealpaste

Delete all recent work?

This removes the 0 items saved in this browser. Your settings stay.

Stop saving recent work?

New work won't be saved in this browser. The 0 items already saved can stay or go.

JSON Escape & Unescape

Text

Paste text, or

CtrlV paste · Ctrl↵ run now

Escaped
Ready
Ln 1, Col 1
Runs in your browser. Nothing you paste is uploaded unless you share it.

Escape text so it fits inside a JSON string (quotes, backslashes, newlines), or unescape a stringified JSON value back to text

Escape text to put it inside a JSON string, or turn an escaped string like {\"a\":1} back into readable text.

How to use it

  1. Choose Escape or Unescape. For Escape, turn on Wrap in quotes to get a complete JSON string, "…" included.
  2. Paste the text. Unescape accepts it with or without the surrounding quotes, and names the line and column of a backslash or quote that breaks it.
  3. Copy the result. To read escaped JSON, unescape it and open it in the JSON formatter .

Examples

Escape a Windows path and quotes

Input
He said "hi"
C:\temp
Result
He said \"hi\"\nC:\\temp

Unescape a log field

Input
{\"event\":\"signup\",\"ok\":true}
Result
{"event":"signup","ok":true}

Common in logs and message queues where JSON is stored as a string inside JSON.

Read \u escapes

Input
caf\u00e9 \ud83d\ude00
Result
café 😀

Four hex digits are one UTF-16 unit, so an emoji past U+FFFF takes two of them (a surrogate pair).

What gets escaped

Inside a JSON string, these characters must be written with a backslash (RFC 8259, section 7):

  • Everything else stays as it is: letters with accents, emoji, single quotes and the forward slash /. JSON allows \/ but doesn’t require it.
CharacterEscaped as
" (double quote)\"
\ (backslash)\\
Line break\n
Carriage return\r
Tab\t
Backspace, form feed\b, \f
Other control characters (U+0000 to U+001F)\u0000 style, e.g. \u001b for the Esc character
Half of an emoji pair on its own (lone surrogate)\ud83d style

Sources: RFC 8259: Strings

A JSON string is not a JavaScript or shell string

The same text needs different escapes in each place it is pasted. JSON is the strictest: double quotes only, no \x or \', and no raw line breaks. A JSON string pasted into a shell needs the shell’s quoting around it as well.

JSONJavaScriptBash
Quotes"…" only"…", '…' or `…`'…' (literal), "…" (expands $)
\x41, \'Not allowedAllowedOnly inside $'…'
\u{1F600}Not allowed: write \ud83d\ude00AllowedNot allowed: $'\U0001F600' (Bash 4.2+)
Line breakMust be \nRaw only in `…`Raw inside quotes
A single quoteAs is\' inside '…'End, \', reopen: 'it'\''s'

Sources: ECMAScript: string literals, Bash manual: quoting

Escaping in code

Escape is what JSON.stringify does to a string, and Unescape is JSON.parse of a quoted string. In Python, json.dumps and json.loads do the same, but json.dumps also writes é and emoji as \u escapes unless you pass ensure_ascii=False.

JSON.stringify('He said "hi"')   // "He said \"hi\""
JSON.parse('"C:\\\\temp"')      // C:\temp

json.dumps("café", ensure_ascii=False)  # "café"

Questions

Why is my JSON full of backslashes?
It was stringified twice: a JSON document was stored as a string inside another JSON value (common in logs, SQS/SNS messages and some databases). Unescape it once to get the inner JSON back.
Are single quotes escaped?
No. JSON strings use double quotes, so single quotes are allowed as they are.
Is my text uploaded?
No. Everything runs in your browser, so your text stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first.

Related tools