{ }JSON Stringify

JSON escape · unescape

JSON Escape: Escape and Unescape JSON Strings

Escape JSON into a quoted string literal, or unescape a JSON string back to readable JSON. Free, runs in your browser, nothing is uploaded.

Runs entirely in your browser — nothing you paste is uploaded

JSON input0 chars
Escaped string—

Everything runs in your browser. Nothing is sent anywhere.

What JSON escape and JSON unescape mean

JSON is text, but it is not a string literal. The moment you need to put a piece of JSON inside something that is already a string — a line of JavaScript, a Java constant, a PHP array value, an environment variable, a database column, a URL parameter, a log entry, a curl command — every double quote in the JSON has to be escaped with a backslash, and the whole payload has to be wrapped in quotes.

JSON escape is that pass: take JSON text, turn every double quote into a backslash-quote pair, turn every newline into \n, and hand back a quoted, escaped string literal. JSON unescape is the reverse: take that quoted blob and get readable, indented JSON back. Both directions run in your browser on this page — pick the tab above.

Escape sequences at a glance

JSON only defines a small set of escapes. Everything else must be written as a Unicode escape:

  • \" — a double quote inside the string
  • \\ — a literal backslash
  • \/ — a slash; legal, but you never actually need it
  • \b \f \n \r \t — backspace, form feed, newline, carriage return, tab
  • \uXXXX — any other control character, from U+0000 to U+001F

Note that \u003c (a less-than sign) is valid but unnecessary. If the JSON ends up inside HTML or an XML attribute you escape <, > and & separately at that layer — those are HTML rules, not JSON rules, and people mix the two up all the time.

When you actually need an escaped JSON string

  • Hard-coding a fixture. You copied a real API response into a test file or a seed script and need it as a single line of source code.
  • Embedding JSON in a config value. Environment variables, .env files, Helm values, CI secrets and YAML fields are all strings; JSON inside them needs escaping (or a block scalar, if the format has one).
  • Nested JSON. A JSON field whose value is itself a JSON string — common in event pipelines, webhooks and queue payloads. That is double serialisation, and the output looks exactly like an escaped string.
  • Building code snippets. Generating a Java, C# or PHP source file that contains a JSON constant.
  • Reading logs. A log line shows a wall of escaped quotes and you want to see the payload again. Paste it in the string → JSON tab.

Escaping in each language

  • JavaScript / TypeScript — JSON.stringify(JSON.stringify(value)). The first call returns JSON text, the second returns the escaped literal. JSON.parse twice goes back. The details are in our JSON.stringify in JavaScript guide.
  • Python — json.dumps(json.dumps(obj)), or json.dumps(obj) followed by json.dumps(text); json.loads twice reverses it. ensure_ascii=False keeps non-ASCII characters readable instead of \uXXXX.
  • PHP — json_encode(json_encode($value)), and json_decode(json_decode($s, true), true) to come back.
  • Java — Jackson's ObjectMapper.writeValueAsString twice, or JsonStringEncoder.getInstance().quoteAsString for the string pass alone.
  • Go — json.Marshal(value) gives JSON bytes; marshal the resulting string again for the escaped form.
  • C# — JsonSerializer.Serialize(JsonSerializer.Serialize(value)).
  • SQL — json_quote() in SQLite, quote_literal() in PostgreSQL, JSON_QUOTE() in MySQL.

Escape is not encodeURIComponent, and not Base64

The three are not interchangeable:

  • Escaping keeps the text human-readable; it just neutralises the characters that would end a string early. Great for source code, bad for URLs.
  • encodeURIComponent turns spaces, &, ? and non-ASCII into percent triplets. That is what a query string needs.
  • Base64 produces opaque ASCII that is safe for binary or for transport headers, but nobody can read it.

If a value is going into a URL, escape it and then percent-encode it, or pass it as a Base64 or compressed parameter instead.

Mistakes that cost people an afternoon

  • Double-escaping. Every escape pass doubles the backslashes, so a payload escaped twice has twice as many as one escaped once. If the output looks like a wall of backslashes, the input probably came out of a database column or a log line that was already escaped — unescape it once first and compare.
  • The wrong direction. Escaping text that is already a string literal adds a second layer that the receiving code will not remove. Decide which side of the boundary you are on before you press Convert.
  • Single quotes. JSON has no single-quoted strings. Fix them before converting.
  • Raw newlines. A literal line break inside a JSON string is invalid; it has to be \n (or \r\n).
  • Emoji and accents. Characters outside the Basic Multilingual Plane (emoji, some CJK) are written as surrogate pairs, \ud83d\ude00. That is normal — unescaping restores the emoji.
  • Assuming escape is protection. An escaped string is one function call away from plain text. It is not encryption.

How to use the two tabs

JSON → escaped string: paste JSON in the left pane and press Convert. The left pane parses your input first, so you get a line-and-column error instead of a broken literal when the JSON is invalid.

String → JSON: paste the quoted, escaped text. Choose 2 spaces, 4 spaces or minified output, and press Convert. Escaped newlines inside string values are unescaped too, which is what makes double-serialised payloads readable again.

Need the plain JSON → text direction instead, or a JavaScript object literal? The JSON stringify converter and the JSON to string page cover those.

Privacy

Everything happens in the browser tab. Nothing you paste is uploaded, logged or stored, so the page is safe for payloads that contain customer records, tokens or internal URLs.

How do I escape a JSON string in JavaScript?

In JavaScript, run JSON.stringify twice: the first call returns JSON text, the second returns a quoted, escaped string literal. To go back, run JSON.parse twice — or paste the escaped text into the string → JSON tab on this page.

What is the difference between escape and unescape?

Escaping wraps the JSON as a string literal: quotes become \" and newlines become \n, so the text can be dropped into source code or a config value. Unescaping is the opposite direction — it removes those backslashes and gives you readable JSON again.

Why does my escaped string look wrong?

Control characters like a tab or a newline, emoji (which travel as surrogate pairs such as \ud83d\ude00), and any character outside plain ASCII are the usual chokepoints. If the result is broken, check the backslashes first: four in a row means the text was escaped twice.

Is my JSON uploaded anywhere?

No. The conversion uses the browser's own JSON functions. Nothing is sent to a server, so customer data, API keys and internal URLs stay on your machine.

Why do I get an error saying the text is not valid JSON?

After unescaping you should have JSON. The common causes are single-quoted keys, a trailing comma, a literal line break inside a string, or an outer quote that was cut off when you copied. The tool reports the position so you can fix the input.