Convert JSON to String
Escape a JSON object or array into a single string literal — the form you need when embedding JSON
inside another string context, like a .env value, a C# or Java string constant, a shell
argument, or a nested field inside a larger JSON payload. Paste your JSON below and get back a string
with quotes, backslashes, and newlines properly escaped.
Need the reverse? Convert String to JSON. Want both directions in one place? Use the combined tool.
Example
Input — raw JSON:
{
"name": "Alice",
"role": "admin"
}
Output — escaped string:
{\"name\":\"Alice\",\"role\":\"admin\"}FAQ
Why do I need to escape JSON into a string?
Raw JSON contains quotes, backslashes, and newlines that would break out of whatever string context you're embedding it in — a .env value, a code string literal, a shell argument, a nested JSON field. Escaping turns those characters into safe sequences (\", \n, ...) so the outer string stays syntactically valid.
Does this handle nested JSON and special characters?
Yes. The input is parsed as real JSON first (any depth of nesting), then every character that needs escaping — quotes, backslashes, control characters, and optionally non-ASCII Unicode — is escaped correctly, not just pattern-matched.
Is my data uploaded anywhere?
No. The conversion runs entirely in your browser (compiled to WebAssembly) — nothing is sent to a server.
What's the difference between this and JSON.stringify()?
JSON.stringify(obj) turns a JavaScript object into JSON text. This tool starts one step further along: you already have JSON text, and you want it re-escaped into a string literal — roughly JSON.stringify(JSON.stringify(obj)) — plus it gives you control over indentation and Unicode escaping without writing any code.