CalcCafe

JSON to String

Convert JSON into a single escaped string you can drop into code, a log line or a string field.

Example

Input
{"a":1,"b":[2,3]}
Output
"{\"a\":1,\"b\":[2,3]}"

How it works

Your JSON is parsed, compacted to one line, and escaped into a quoted string literal. The result is safe to embed wherever a string is expected.

Good to know

JSON to String takes a JSON object or array and turns it into a single, escaped string literal — the kind you can paste directly into source code, a config value, a log message, or a database text field. It does this by parsing your input, collapsing it onto one line, escaping every double quote and special character, and wrapping the whole thing in outer quotes. It's aimed at developers who need to embed JSON as a string rather than as raw structured data.

You'd reach for this whenever JSON has to travel inside something that only accepts a string. Common cases include hardcoding a payload into a test fixture, storing a JSON blob in a column that isn't a native JSON type, passing JSON as an environment variable, sending it as a string value inside a larger request body, or logging a structured event on a single line. In each of these the inner quotes must be backslash-escaped so the surrounding parser doesn't break on them.

Reading the output is straightforward once you know the pattern: the result begins and ends with a quote, and every " from your original JSON becomes \". So {"a":1} becomes "{\"a\":1}". The visible backslashes are not part of your data — they are escape characters that disappear the moment the string is parsed back into JSON.

A practical caveat: this is single-level escaping, valid for embedding once. If you nest the result inside another string layer, you'll need to escape it again, and the backslashes multiply quickly. To go back the other way, run the output through a JSON unescape or parse step rather than manually deleting backslashes, since hand-editing is error-prone for large payloads.

Frequently asked questions

How is this different from minify?
Minify gives you compact JSON; this also escapes it and wraps it in quotes, producing a string literal rather than raw JSON.
Can I reverse it?
Yes — use the JSON Unescape tool to turn an escaped string back into raw JSON.
Is my JSON uploaded anywhere?
No — everything runs in your browser with JavaScript. Your data never leaves your device, so it's safe for sensitive payloads and works offline once loaded.
Is this tool free?
Yes, completely free with no sign-up and no limits.

More JSON tools

People also ask

What does it mean to escape JSON into a string?
Escaping JSON means converting the JSON text into a string literal by adding backslashes before characters that would otherwise end or break the string, mainly double quotes. The escaped version can be safely stored or embedded inside another quoted value and parsed back later to recover the original JSON.
Why are there backslashes before the quotes in the output?
The backslashes are escape characters that tell a parser the following double quote is part of the string content, not the end of the string. They are not stored in your actual data and are removed automatically when the string is parsed back into JSON.
How do I embed a JSON object inside another JSON value?
Convert the inner JSON to an escaped string first, then place that string as the value. The inner object's quotes become \" so the outer JSON stays valid, and the receiving code parses the string a second time to get the object back.
What is the difference between stringify and escaping JSON?
JSON.stringify turns a live data object into JSON text, while escaping takes existing JSON text and wraps it as a quoted, backslash-escaped string literal. Stringifying a string that already contains JSON effectively performs the escaping step.
How do I convert an escaped JSON string back to normal JSON?
Parse or unescape it once: removing the outer quotes and turning every \" back into " yields the original JSON. Most languages do this automatically when you call their JSON parse function on the escaped string, or you can use a dedicated unescape tool.
Will escaping change the data inside my JSON?
No. Escaping only adds backslashes and outer quotes around the text representation; the keys, values, and structure are unchanged. After unescaping you get back byte-for-byte the same JSON you started with.
Can I store JSON in a plain text database column this way?
Yes. Converting JSON to an escaped string lets you store it in a text field, though many databases also offer native JSON column types that avoid manual escaping. The escaped form is most useful when the storage or transport layer only understands plain strings.
Is it safe to convert sensitive JSON in an online tool?
This tool runs entirely in your browser using JavaScript, so the JSON is processed locally and is not uploaded to a server. That makes it usable for sensitive payloads and it continues to work offline once the page has loaded.