About the JSON Stringify
Run JSON.stringify on your JSON to get an escaped string literal that you can embed in source code, config values or another JSON document.
Key features
- Runs JSON.stringify on your JSON to produce an escaped string
- Optional minification so the string has no \n sequences
- Ready to embed in code, configs or another JSON document
- Validates input before stringifying
- Unicode-safe output
- Instant and private
What does stringifying JSON do?
Stringifying converts JSON into a JSON string: the whole document wrapped in quotes with internal quotes and special characters escaped. The output is a single string value that can safely be placed inside another JSON document, a JavaScript file, an environment variable or a database text column.
Example
JSON:
{ "event": "signup", "plan": "pro" }
Stringified (minified first):
"{\"event\":\"signup\",\"plan\":\"pro\"}"
Now it can be nested as a value:
{ "type": "message", "body": "{\"event\":\"signup\",\"plan\":\"pro\"}" }
Where stringified JSON is required
| System | Field that expects a JSON string |
|---|---|
| AWS SNS / SQS | Message / MessageBody |
| AWS Step Functions | input when starting executions via API |
| Azure Service Bus / Event Grid | Some message bodies |
Browser localStorage | Every value |
| SQL text / VARCHAR columns | JSON stored as text |
| Some webhook and logging APIs | Payload or data fields |
In code
const asString = JSON.stringify(JSON.stringify(data)); // double-encoded
const original = JSON.parse(JSON.parse(asString)); // and back
Common pitfalls
- Double encoding by accident. If you see
\\\"in your data, something was stringified twice. Use JSON Unstringify to unwrap it. - Forgetting to parse. Consumers must call
JSON.parseon the field to get an object again. - Size. Escaping adds a backslash before every quote, so stringified JSON is larger.
Related tools
Reverse it with JSON Unstringify. To create a language-specific string literal (Java, C#, Python), use JSON to String.
How to use the JSON Stringify
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The result appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.