JSON ↔ String
Stringify JSON into an escaped string literal for code, or parse a string back to JSON, locally.
Turn JSON into an escaped string literal for code
This tool converts a JSON document into a single escaped string literal, the form you need when embedding JSON inside a source file, a shell command or an environment variable, and it converts that literal back into readable JSON. It accepts a quoted literal, a bare escaped body, or plain JSON on the way back, so you don't have to know which form you're holding. Nothing you paste leaves your browser.
How to use the JSON ↔ String
- Paste valid JSON on the left to get a minified, escaped string literal.
- Copy the quoted output straight into source code, JSON config, or a shell variable.
- Switch to String → JSON to paste a literal or an escaped body instead.
- Use Send To if you want to hand the result to another tool directly.
The JSON → String direction first validates and minifies the input, then wraps it in double quotes and escapes embedded quotes, backslashes and control characters, matching what JSON.stringify produces for a string value. The reverse direction accepts a quoted literal, an unquoted escaped body, or already-valid JSON, and pretty-prints the result with two-space indentation.
Frequently asked questions
- Why would I need to turn JSON into a string?
- Some contexts, like a Java or C# string literal, a shell environment variable, or a JSON field that itself holds JSON text, need the document escaped into a single quoted string rather than raw JSON. This tool produces that exact form.
- Does this validate the JSON before escaping it?
- Yes. The input is parsed with JSON.parse first, so invalid JSON produces an error instead of an escaped string; you can't accidentally stringify malformed input.
- What input formats work in the String to JSON direction?
- A quoted literal, a bare escaped body without surrounding quotes, and already-valid raw JSON are all accepted; the tool detects which form you pasted and parses accordingly.
- Can I control the indentation of the resulting JSON?
- The String → JSON output is pretty-printed with two-space indentation by default; there's no control in the interface to change it to four spaces or tabs for this direction.