{}JSONLint.app

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

Common Mistakes & Pro Tips

  • Stringify turns a value into a quoted string literalJSON.stringify wraps your JSON in an extra layer: the object {"a":1} becomes the string "{\"a\":1}", with internal quotes escaped. This is exactly what you need to embed a JSON payload inside another JSON document or paste it as a string constant in source code.
  • Stringify is not the same as minifyMinify returns valid JSON of the same value; stringify returns a JSON string whose content is the original JSON text. If you stringify and then parse once, you get the original string of JSON, not the object; you must parse twice to reach the value.
  • Each round of stringify adds another escape layerCalling stringify on already-stringified text doubles the backslashes (\" becomes \\\"). This double-encoding is a frequent cause of unreadable payloads; track how many times your data has been stringified so you parse exactly that many times to unwrap it.
  • Functions, undefined, and symbols are dropped or nulledJSON.stringify omits object properties whose value is a function, undefined, or a symbol, and converts those same values to null inside arrays. This is JavaScript-specific behavior; it matters when you serialize live objects rather than already-clean JSON text.
  • Special numeric values do not surviveNaN, Infinity, and -Infinity are serialized as null by JSON.stringify because RFC 8259 has no representation for them. If your data can contain these, encode them as strings or sentinels before stringifying so the information is not lost.

Frequently Asked Questions

What is the difference between stringify and escape?

Stringify takes a whole JSON value and returns a quoted, escaped string literal representing it, including the surrounding double quotes. Escape takes a raw string and only escapes the characters that are unsafe inside a JSON string, without value-level conversion or adding outer quotes unless you ask. Stringify is value-to-literal; escape is string-content-to-safe-content.

How is stringify different from minify?

Minify keeps the result as JSON of the same value, just without extra whitespace. Stringify changes the type: the output is a JSON string whose characters are the original JSON text, with quotes and backslashes escaped. Parsing minified JSON gives your object; parsing stringified JSON gives back the JSON text as a string.

Why does my stringified JSON have so many backslashes?

Every double quote inside the value must be escaped as \" when it lives inside an outer string, so a JSON object full of quoted keys gains a backslash before each one. If you see doubled or tripled backslashes, you have likely stringified the same data more than once.

How do I embed a JSON object as a string inside another JSON file?

Stringify the inner object once, then place the resulting quoted string as the value of a key in the outer document. The consumer reads that key, gets a string, and calls parse on it to recover the inner object. This nested-JSON pattern is common in message queues and webhook payloads.

Why did my function or undefined value disappear after stringify?

JSON has no type for functions, undefined, or symbols, so JSON.stringify omits such properties from objects and replaces them with null inside arrays. If you need them, convert to a JSON-representable form first, such as a string flag or a number.

Is the stringified output produced on my machine?

Yes. The conversion happens in your browser via JavaScript's built-in JSON.stringify, so your data never leaves your device. That makes it safe to stringify credentials, tokens, or internal payloads you would not want sent to a remote server.