toolgarden.xyz
中文

JSON Escape

Free online JSON escape tool to minify and escape JSON / JSONC / JSON5 for embedding in strings, or unescape back

Input

Output

Result will appear here

About this tool

JSON escaping solves the syntax collision that appears when one JSON document must live inside another string. Quotes, backslashes, line breaks, and tabs already have meaning to the host string; escaping replaces them with backslash sequences without changing the underlying data.

The tool parses and minifies the document before escaping it, so malformed JSON is reported instead of being wrapped as a plausible-looking string. Unescape performs the reverse operation for JSON copied from logs, environment variables, or source code.

How to use it

  1. Choose the direction

    Use minify and escape before embedding JSON in a string. Use unescape when backslash sequences need to become readable JSON again.

  2. Paste the complete value

    Escape mode expects parseable JSON. Unescape mode expects the string contents without an extra pair of host-language quotes.

  3. Inspect and copy

    Check quotes, line breaks, and backslashes against the syntax required by the destination, then copy the result.

Input and output example

What one JSON document looks like once escaped to sit inside another as a string value. Note the backslash before every double quote.

Original JSON
{
  "host": "db.internal",
  "port": 5432
}
Escaped, usable as a string value
"{\"host\":\"db.internal\",\"port\":5432}"

Supported range and limits

Two directions
Minify and escape into an embeddable string, or unescape back into readable JSON
Characters escaped
Double quotes, backslashes, newlines, tabs, carriage returns and other control characters
Why you need it
Putting JSON inside another JSON document, a config field or a database column requires escaping first
What unescaping is for
Recovering text copied from logs or database columns where every quote carries a backslash
Nesting
Two levels of nesting need two rounds of escaping, and the same in reverse; the wrong count fails to parse
Where it runs
Entirely in the browser; the input is never uploaded

When you would use it

  • Storing configuration in an environment variable

    Turn a multi-line config into one escaped line for a CI setting or container variable that only accepts strings.

  • Reading a structured log field

    Logging systems often JSON-encode a request body a second time. Unescape it before formatting and inspecting its fields.

  • Embedding JSON inside JSON

    When an API field has to carry a whole JSON document, it must be escaped into a string before it can travel as a value.

What to know before you start

  • JSON escaping is not URL encoding or Base64. Use the representation named by the receiving system documentation.
  • Unescape interprets backslash sequences. A literal backslash must already be doubled or it can be consumed as a control escape.
  • JSONC and JSON5 extensions are normalized to strict JSON during parsing, so comments are not retained.

Related concepts

escape sequence
A backslash-prefixed spelling for characters that cannot be written literally inside a string, such as \n for a line break.
double encoding
The same data is wrapped as a JSON string more than once, usually visible as repeated backslashes. Remove only one layer at a time.

Frequently asked questions

What is the difference between escaping and unescaping JSON?
Escaping minifies the JSON to one line and backslash-escapes quotes, newlines and other special characters so it can be embedded in a string; unescaping restores an escaped string back to readable JSON.
When do I need to escape JSON?
When you want to place a piece of JSON as a string value inside another JSON document, code or database field, escape it first so quotes and newlines don't break the structure.
Does escaping upload my data?
No. Both escaping and unescaping run locally in your browser and nothing is uploaded to a server.
Why do the backslashes keep multiplying?
Each level of nesting escapes again. JSON inside JSON is two levels; a third level gives you four backslashes. Unescape exactly as many times as you escaped, or parsing fails.
Is escaping the same as URL encoding?
No. JSON escaping handles characters special to JSON syntax; quotes, backslashes, newlines. URL encoding handles characters reserved in a URL. JSON going into a query parameter usually needs both, escaping first and URL encoding second.