Paste JSON to escape it as a string, or paste an escaped string to unescape it:

Loading...
Loading...

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 values

Storing 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

CharacterEscaped AsWhy
"\\"Would end the string
\\\\\\Escape character itself
Newline\\nInvalid in JSON strings
Tab\\tControl character
Carriage return\\rControl 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 \\\\n instead 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