Paste JSON to escape it as a string, or paste an escaped string to unescape it:
What is JSON Stringify?
JSON Stringify converts a JSON object into an escaped string. The result can be safely embedded inside another stringβin code, databases, or even nested within other JSON. All quotes, newlines, and special characters get escaped so they don't break the containing context.
Before and After
Original JSON:
{
"message": "Hello, World!",
"count": 42
}Stringified:
"{\"message\": \"Hello, World!\", \"count\": 42}"When You Need This
Embedding JSON in JavaScript strings
const jsonTemplate = "{\"name\": \"$name\", \"id\": $id}";
// Later: replace $name and $id with actual valuesStoring JSON in a database text field
Some databases or ORMs expect a plain string. Stringifying ensures quotes and special chars don't corrupt the data.
Nesting JSON inside JSON
{
"type": "log",
"payload": "{\"level\":\"error\",\"msg\":\"Something failed\"}"
}The inner JSON is a string value, not a nested object. This pattern is common in logging systems and message queues.
Sending JSON in URL parameters
While URL encoding is usually better, sometimes you need to pass JSON as a query parameter. Stringifying is the first step.
Characters That Get Escaped
| Character | Escaped As | Why |
|---|---|---|
" | \\" | Would end the string |
\\ | \\\\ | Escape character itself |
| Newline | \\n | Invalid in JSON strings |
| Tab | \\t | Control character |
| Carriage return | \\r | Control character |
Stringify vs. Serialize
These terms are often used interchangeably, but technically:
- JSON.stringify() β Converts a JavaScript object to a JSON string
- This tool β Takes JSON (already a string) and escapes it for embedding
If you have a JavaScript object and want JSON, use JSON.stringify(obj). If you have JSON text and need it escaped, use this tool.
Programmatic Usage
In JavaScript, double-stringify to get the escaped version:
const obj = { message: "Hello" };
const json = JSON.stringify(obj); // '{"message":"Hello"}'
const escaped = JSON.stringify(json); // '"{\"message\":\"Hello\"}"'To reverse (unescape):
const escaped = '"{\"message\":\"Hello\"}"';
const json = JSON.parse(escaped); // '{"message":"Hello"}'
const obj = JSON.parse(json); // { message: "Hello" }Pro Tips
- π‘ Check for double-escaping β If you see
\\\\ninstead of\\n, you've stringified twice - π‘ Validate after unescaping β Use the JSON Validator to confirm you got valid JSON back
- π‘ Watch for encoding issues β Non-ASCII characters might need additional handling depending on your system
Related Tools
- JSON Validator β Validate and format JSON
- JSON Diff β Compare JSON documents
- XML to JSON β Convert XML to JSON