# Format JSON without changing the data

> Make a payload readable while keeping large identifiers, string escapes and duplicate keys visible. Separate syntax validation from data validation.

- Canonical HTML: [https://unrust.dev/blog/format-json-without-changing-data](https://unrust.dev/blog/format-json-without-changing-data)
- Markdown representation: [https://unrust.dev/blog/format-json-without-changing-data/index.md](https://unrust.dev/blog/format-json-without-changing-data/index.md)

Published: 2026-10-16. By the Unrust team.

[Open the companion tool](https://unrust.dev/tools/json-formatter/index.md)

## Keep a copy of the original payload

Suppose a webhook contains the identifier 9007199254740993. You want to indent the payload so you can inspect its fields. The formatting task should not change that identifier, reorder the fields or decide which repeated key wins. Keep the original response alongside the formatted view so you can compare them if a later step behaves differently.

Paste the example below into the JSON formatter. The output adds line breaks and indentation while retaining the exact number text. Switch to Minify and check that the identifier is still 9007199254740993. This tool changes whitespace outside strings after validating the syntax.

```json
{"event":"clip.ready","id":9007199254740993,"published":false}
```

## Why a parse-and-stringify shortcut can change a number

JavaScript numbers cannot represent every integer above the safe-integer range. A formatter that parses a payload into ordinary numbers and then serializes those numbers can change a large integer. That is especially awkward for an identifier: a nearby integer is a different record, not an acceptable approximation.

Unrust validates the JSON but does not serialize the parsed value to produce the output. It retains the original numeric text instead. That preserves this file’s representation; it does not guarantee that the service receiving the file will also preserve it. If you control an API contract, agree on an appropriate representation for identifiers, such as decimal strings, and test the actual producer and consumer.

## Valid syntax still leaves questions to answer

The payload below is valid JSON syntax even though it contains the same key twice. The formatter preserves both entries so the ambiguity remains visible. Decide whether your application should reject duplicate names and where that validation belongs. Do not rely on pretty indentation to resolve the contract.

Syntax validation also cannot tell you whether a required field is missing, a date is meaningful, an identifier exists, or the caller may perform an action. Follow it with schema and domain checks suited to the application. Use the formatted view to inspect those checks more easily.

```json
{"retries":0,"retries":3,"published":"false"}
```

## Inspect types and escapes before changing values

In that example, "false" is a string, not a Boolean. If the consumer expects a Boolean, formatting will not fix the mismatch. Similarly, an empty array, null and an absent field can carry different meanings. Read the data contract before replacing one with another.

Strings may contain escaped quotes, backslashes and line breaks. The formatter keeps their original escapes. A visible \n inside a JSON string is part of the encoded value, while an actual formatting newline between fields is whitespace. Keep that distinction when comparing a compact payload with an indented one.

## Use the result as a review aid

Download the formatted JSON when you need a readable fixture, or copy minified output when you need a compact representation. Re-run the application’s own validation and relevant tests after making a real value change. A locally valid document may still violate an API’s expectations.

This utility accepts up to 200,000 input characters and 100 nesting levels. It processes the text in your browser and does not execute it. For a large production payload, use your normal local tooling and preserve the original evidence. The purpose is to expose the data clearly enough to ask better questions about it.

## References and next steps

[MDN: JSON and lossless number serialization](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)

[Build a habit of reading code carefully](https://unrust.dev/guides/reading-code-against-a-contract/index.md)

[Take the free diagnostic without tools or hints](https://unrust.dev/diagnostic/index.md)
