"category": "utility",
JSON Stringify - Escape JSON as a String
"tldr": Paste JSON and get it as an escaped string literal - minified, quoted, and ready to embed inside another JSON document or code.
Turn a JSON document into an escaped string literal: the input is validated, minified, and wrapped in quotes with every inner quote escaped - the exact form you need when a JSON document must live inside a JSON string field, a code literal, or an environment variable.
This "JSON inside JSON" shape appears everywhere: webhook payload fields, database TEXT columns, message-queue envelopes, and Terraform/CloudFormation templates. Doing the escaping by hand is the fastest way to produce the parse errors our error guides exist for.
How to stringify JSON
- 1Paste your JSON - it is validated first, so you never stringify a broken document.
- 2The document is minified, then escaped into a double-quoted string literal.
- 3Paste the result as a value inside another JSON document or a code string.
- 4To reverse it, use our JSON Unescape tool.
Convert JSON to String literal in code
const payload = { event: "order.created", data: { id: 1042 } };
const embedded = JSON.stringify(JSON.stringify(payload));
// "{"event":"order.created",...}" - paste as a JSON string valueimport json
payload = {"event": "order.created", "data": {"id": 1042}}
embedded = json.dumps(json.dumps(payload))Frequently asked questions
How is this different from JSON minify or JSON escape?
Minify outputs the same JSON, just compact. Escape treats input as arbitrary text. Stringify does both steps for JSON specifically: validate → minify → escape into one string literal, i.e. JSON.stringify applied to a JSON string. Three tools because the three intents produce different output.
When would JSON legitimately live inside a JSON string?
Envelope patterns: a queue message with a "payload" string field, audit logs storing the raw request body, webhook signatures computed over the exact string, and APIs that forward opaque documents without parsing them. It costs double parsing on the consumer side - use nested objects instead when you control both ends.
Why is the output minified first?
Escaped newlines (\n) and indentation spaces survive stringification and bloat the literal by 30-50% while adding nothing - the inner document parses identically. Minifying first keeps the embedded string as small as possible.
How do I do this in code?
JavaScript: JSON.stringify(JSON.stringify(obj)) - the inner call serializes, the outer escapes. Python: json.dumps(json.dumps(obj)). If you find yourself doing it more than twice in one payload, reconsider the envelope design.
Last updated:
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →