Skip to content
TypeParser
All tools

JSON Stringify / Escape

Escape JSON for embedding in code.

beats freeformatter.com edge: Round-trip safe + escape preview
raw
escaped
Guide

About JSON Stringify / Escape

Wrap any text or JSON in proper <code>JSON.stringify</code> output — escape quotes, newlines, control chars, and unicode. Useful for embedding payloads in shell scripts, environment variables, config files, or other JSON. Round-trip safe — what we produce can be safely <code>JSON.parse</code>'d back to the original.

Why this is its own tool

JSON.stringify is one line in JavaScript, but you reach for it from a context where you cannot run JavaScript — bash, a config form, a CI YAML field. A web tool replaces the awkward in-shell escaping dance.

Use case examples

Embed JSON in a shell script:

curl -X POST -d "$(cat <<EOF
{"key": "value", "nested": {"path": "ok"}}
EOF
)" https://example.com

vs. with stringified payload:

curl -X POST -d '{"key":"value","nested":{"path":"ok"}}' https://example.com

The latter is single-quote-safe — no shell expansion, no heredoc dance.

Embed JSON in a TS string:

const FIXTURE = "{\"key\":\"value\",\"items\":[1,2,3]}";
JSON.parse(FIXTURE);

Embed JSON in YAML:

config: '{"feature":"on","retries":3}'

Common workflows

Build a webhook payload by hand. Compose JSON, stringify it, paste into your test runner.

Move a fixture across formats. JSON in a .env value? Stringify before assignment.

Test escape edge cases. Paste content with quotes, backslashes, newlines. Confirm the result parses cleanly back.

Why local

The string you stringify is often meaningful payload — request body, fixture, config. Pasting into a remote tool exposes it. Local browser-side stringify with no logging, no transmission.

Frequently asked questions

When do I need this?
Embedding JSON inside JSON, or wrapping a multiline string for use as an env var, or building a curl command line. Anywhere you need a string that looks like JSON to a parser but is itself a JSON value.
What gets escaped?
Double quotes (") become \". Backslash becomes \\. Newline → \n. Tab → \t. Control chars → \uXXXX.
What about non-ASCII?
Optional. Toggle Escape non-ASCII to render café as café — useful for systems that mishandle UTF-8.
Will it pretty-print before stringifying?
Toggle. With pretty-print on, the wrapped string preserves readable indentation; with it off, you get compact one-line JSON.
Is it round-trip safe?
Yes. Stringify → Parse → original input, byte-identical for JSON inputs and textually equivalent for raw strings.
Can I unescape too?
Yes. Toggle Unescape to reverse the operation — paste an escaped string, get the raw form.

Related tools

Last updated: 2025-01-15