# JSON Formatter

> Validates a complete UTF-8 JSON document and rewrites only the whitespace that JSON defines as insignificant. Readable and minified output preserve key order, duplicate names, string escapes and every original number token.

Use it: https://tessalor.com/en/data/json-formatter

This tool runs entirely in the browser. Nothing entered into it is uploaded.

## How it is done

1. Read the file as strict UTF-8. Accept and consume an initial UTF-8 byte-order mark for compatibility, but do not write one into the result.
2. Validate the complete document as one RFC 8259 JSON value before producing an artifact. Refuse an empty file, invalid UTF-8, trailing content or malformed objects, arrays, strings, numbers and literal names.
3. Scan the validated source while tracking quoted strings and backslash escapes. Inside a string, copy every code unit exactly; outside a string, discard only space, tab, carriage return and line feed.
4. For readable output, insert the selected indentation after an opening container and comma, one space after a colon, and a correctly indented line before a non-empty closing container. For minified output, insert no optional whitespace.
5. Encode the rewritten text as UTF-8, add one final line feed only when selected, and offer a new .json file. Never parse number tokens into floating-point values for output.

## Assumptions

- Formatting is not canonicalisation. Object member order, duplicate names, number spelling and string escape choices stay as authored even where another parser might normalise or collapse them.
- JSON exchanged between independent systems is UTF-8 under RFC 8259. UTF-16 and legacy code pages belong in the separate text-encoding converter before this grammar is applied.
- The native JSON parser is used as a strict grammar validator only. The downloadable bytes come from a token-preserving scan of the original text, not from JSON.stringify.
- Input is capped at 25 MB. The rewrite yields every 250,000 characters so progress and Cancel remain responsive; native validation itself is intentionally left to the browser's optimised parser.

## Inputs

| Name | Label | Type | Default | Range |
| --- | --- | --- | --- | --- |
| `source` | JSON file | file | chosen on your device | application/json, text/plain, up to 25 MB |
| `layout` | Output layout | select | pretty |  |
| `indent` | Indent readable JSON with | select | 2 |  |
| `finalNewline` | End the file with a newline | toggle | true |  |

## Outputs

- `outputBytes` — Output bytes (integer), primary
- `inputBytes` — Input bytes (integer)
- `nestingDepth` — Deepest nesting level (integer)
- `layout` — Written as (text)

## Questions

### Does the JSON file leave this device while it is formatted?

No. Strict decoding, grammar validation, whitespace rewriting and file creation happen inside a worker in this browser tab. The generated browser test supplies a real JSON file and fails if tool use sends an off-origin request.

### Can formatting round an integer larger than JavaScript can represent exactly?

Not here. The validator may inspect the grammar, but the writer copies the original number characters rather than serialising a JavaScript Number. An integer such as 9007199254740993 therefore keeps every digit.

### Are duplicate object names removed?

No. RFC 8259 recommends unique names for interoperability but describes inconsistent parser behaviour when duplicates exist. This formatter preserves every member in its original order so formatting does not make that product decision silently.

### Does minifying remove spaces or line breaks inside a string?

No. A quoted string is copied byte-for-byte after UTF-8 decoding, including ordinary spaces and escaped control characters. Only the four JSON whitespace characters found outside a string are optional.

### Will the formatter sort keys or make canonical JSON?

No. Sorting changes member order and canonicalisation also changes token spelling. This tool has one narrow promise: validate the document and change insignificant whitespace only.

## Sources

- [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259.html) — RFC Editor / Internet Engineering Task Force, applies to Standards Track, December 2017. Retrieved 2026-08-01.
- [Encoding Standard](https://encoding.spec.whatwg.org/) — WHATWG, applies to Living Standard, August 2026. Retrieved 2026-08-01.

## Variants

- [How do I format a JSON file without uploading it?](https://tessalor.com/en/data/json-formatter/format-json-file-without-uploading)
- [How do I minify JSON without changing large numbers?](https://tessalor.com/en/data/json-formatter/minify-json-without-changing-numbers)

---

Estimate, not advice. See https://tessalor.com/en/disclaimer.
Machine-readable catalogue: https://tessalor.com/api/tools.json
