Skip to content

JSON Stringify Online

Turn JSON into an escaped string you can put inside another JSON value, a database column or a line of code. Quotes become \", backslashes double, and line breaks become \n.

{"a":1} → "{\"a\":1}"

Valid JSON · object with 4 keys · 2 levels deep · 106 bytes

"{\"message\":\"Hello, \\\"Sam\\\"\",\"folder\":\"C:\\\\Reports\",\"lines\":[\"first\",\"second\"],\"count\":3}"

88 → 112 characters · 22 backslashes added. To turn it back into JSON, use Unstringify JSON.

Same result as JSON.stringify(). Everything runs in your browser; nothing is uploaded.

What is JSON stringify?

Stringifying JSON wraps a whole JSON document in quotes and escapes everything inside, so the document becomes one text value. The result is still valid JSON, but now it is a string rather than an object. Any JSON reader turns it back into the original text, and reading that text gives you the object again.

Before: a JSON object

{"message":"Hello","count":3}

After: a JSON string

"{\"message\":\"Hello\",\"count\":3}"

When you need a stringified JSON

  • JSON inside JSON. Webhooks, message queues and logging tools often carry a payload as a string field:
{"type": "order.paid", "payload": "{\"orderId\":1048,\"total\":23.5}"}
  • A database text column or setting. Some columns, environment variables and config values only take plain text. Stringify the JSON first so its quotes don’t break the value.
  • A string literal in code. Pasting JSON into "…" in a test or a script needs every quote escaped. The output above can be pasted straight in, in JavaScript, Java, C# and most other languages.
  • A URL parameter. Stringifying isn’t enough here. URLs need percent-encoding, so use JSON URL Encode instead.

Characters that get escaped

Only a few characters change. Each gets a backslash in front, so the string’s own closing quote stays the only real one:

Characters JSON.stringify escapes inside a string, and why
CharacterEscaped asWhy
" double quote\"Would end the string
\ backslash\\Starts every escape, so it is doubled
Line break\nStrings must stay on one line
Carriage return\rSame, for Windows line endings
Tab\tControl character
Other control characters\u0000–\u001fInvisible characters can’t appear raw

Each layer adds more backslashes. In the tool’s example, the text Hello, "Sam" is written \"Sam\" inside the JSON, and \\\"Sam\\\" once stringified: the backslash and the quote are each escaped again. Slashes, accents and emoji are left as they are.

Stringify vs serialize

In JavaScript, JSON.stringify(object) serializes an object into JSON text. Calling it on text that is already JSON stringifies it a second time, which is what this tool does:

const order = { id: 7, note: "Hi" };

const json = JSON.stringify(order);   // {"id":7,"note":"Hi"}          serialized
const str  = JSON.stringify(json);    // "{\"id\":7,\"note\":\"Hi\"}"  stringified

JSON.parse(str);                      // '{"id":7,"note":"Hi"}'  (text again)
JSON.parse(JSON.parse(str));          // { id: 7, note: "Hi" }   (the object)

So serializing goes from objects to JSON text, and stringifying JSON goes from JSON text to a JSON string. Undo it by parsing twice, or with Unstringify JSON.

How to stringify JSON in code

// JavaScript
const str = JSON.stringify(JSON.stringify(data));

# Python
s = json.dumps(json.dumps(data))

// PHP: also escapes / as \/ unless you pass JSON_UNESCAPED_SLASHES
$s = json_encode(json_encode($data));

// C#: System.Text.Json writes the quotes as \u0022 by default (still valid)
string s = JsonSerializer.Serialize(JsonSerializer.Serialize(data));

// Java (Jackson)
String s = mapper.writeValueAsString(mapper.writeValueAsString(data));

The inner call serializes the data; the outer call turns that text into a string. All of these produce valid JSON strings, but the exact escapes differ a little between languages, so compare them by parsing, not by eye.

Frequently asked questions

How do I turn a stringified JSON back into an object?

Parse it twice: JSON.parse(JSON.parse(str)) in JavaScript, or json.loads(json.loads(s)) in Python. The first parse gives the JSON text, the second gives the object. Unstringify JSON does the same here.

Why do I see \\\" instead of \"?

The JSON was stringified twice. Each layer escapes the backslashes of the layer before, so the number of backslashes grows: \" after one layer, \\\" after two. Stringify once, and parse once per layer.

Is a stringified JSON still valid JSON?

Yes. It is a JSON string value, so any JSON parser accepts it. It just isn’t an object any more, so code that expects .id or ["id"] needs to parse it again first.

Why does JSON.stringify give "[object Object]"?

That comes from String(obj) or "" + obj, not JSON.stringify. Template strings and + call toString(), which prints [object Object]. Use JSON.stringify(obj) to get JSON.

Sources