Developer Tools Runs in your browser Free · no account

JSON Escape and Unescape

The JSON escape tool converts text into a form that is safe to place inside a JSON string value, escaping quotes, backslashes, newlines, tabs and control characters. The unescape direction converts an escaped string back to the characters it represents, which is useful when reading a log entry containing embedded JSON.

Options
Text 0 characters
Result

Your result will appear here.

Not sure where to start? Use Load example.

Results update automatically and are calculated on your device. Nothing you type is sent to a server.

Runs in your browser. Processing happens entirely in your browser. Nothing you enter is sent to Delimiter.live.

How to use the JSON Escape and Unescape

  1. Paste the text you want to escape, or an already-escaped string to decode.
  2. Choose the direction — escape for JSON, or unescape back to plain text.
  3. Turn the surrounding quotes off if you are pasting the result into an existing string.
  4. Copy the result.

Example

Input
Line one
He said "hi"
Output
"Line one\nHe said \"hi\""

Common use cases

  • Embedding a multi-line snippet inside a JSON configuration value.
  • Reading an escaped JSON payload that was logged as a string field.
  • Preparing text containing quotes for a JSON request body by hand.
  • Decoding a stringified JSON value pulled out of a database column.

Limitations and things to watch for

  • Escaping produces a JSON string, not a full JSON document. Pasting the result where a document is expected will not parse unless it is placed inside one.
  • Unescaping accepts either a fully quoted string or a bare escaped body, but a fragment with unbalanced quotes will be rejected rather than guessed at.
  • Escaping does not make untrusted content safe for HTML. Use the HTML entity encoder for that — JSON escaping and HTML escaping solve different problems.

Frequently asked questions

What characters get escaped?
Double quotes, backslashes, newlines, carriage returns, tabs, form feeds, backspaces and any other control character below U+0020, which are escaped as \u sequences. Ordinary printable text passes through unchanged.
Should I include the surrounding quotes?
Include them when the result is a complete JSON string value on its own. Leave them off when you are pasting the escaped text into the middle of a string you have already opened.
Does escaping protect against injection?
It makes text safe to place inside a JSON string, which prevents it breaking the document structure. It does not make content safe to render as HTML — that needs HTML entity encoding, which is a separate step.
Why does my unescape fail?
Usually a stray backslash or an incomplete \u escape, which needs exactly four hexadecimal digits. The input must be a valid escaped string, either quoted or bare.

Share this tool