JSON Formatter
Pretty-print JSON with configurable indentation — big numbers preserved exactly, entirely on this device.
Compact removes every inter-token space — minified output. Integers beyond 15–16 digits are kept exactly as written instead of being rounded by JavaScript's Number. Applies only to the downloaded file, never the pane. This formatter changes whitespace only — never key order, never values.
Press ? for shortcuts
Do it offline:$ jq . file.json
How to use it
- Paste your JSON, or drop a .json/.txt file onto the input pane. The formatted result appears immediately — there is no button to press for typical inputs.
- Pick an indentation: 2 spaces (the default), 4 spaces, tabs, or compact — compact strips every inter-token space, the same output a minifier produces.
- Leave “Preserve big numbers” on unless you specifically want JavaScript's native number behavior. Off, integers beyond 2⁵³ silently round.
- If the input is invalid, the error tells you the line, column, and probable cause, with a code frame pointing at the exact character. Your input is never modified.
- Use Copy for the raw string, Download for a .json file (LF or CRLF line endings), or Share to put the whole tool state into a link.
Paste JSON — or drop a file up to 50 MB — and the formatted result appears as you type. Everything runs on this device: nothing you paste is uploaded. One invariant governs this page: the formatter changes whitespace only — never key order, never values. Numbers longer than JavaScript can represent are preserved digit-for-digit, which is where most online formatters quietly corrupt your data.
Examples
{"id":42,"name":"café ☕","tags":["a","b"],"nested":{"ok":true,"n":null}}{
"id": 42,
"name": "café ☕",
"tags": [
"a",
"b"
],
"nested": {
"ok": true,
"n": null
}
}The default: 2-space indentation. Key order and every value are untouched.
{"total": 9007199254740993}{
"total": 9007199254740993
}Preserved exactly. JSON.parse alone would emit 9007199254740992 — beyond Number.MAX_SAFE_INTEGER, JavaScript numbers lose precision.
{
"id": 42,
"name": "café ☕",
"tags": [
"a",
"b"
],
"nested": {
"ok": true,
"n": null
}
}{"id":42,"name":"café ☕","tags":["a","b"],"nested":{"ok":true,"n":null}}Compact mode strips every inter-token space — the inverse of formatting, same engine.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Why a formatter must never reorder keys
JSON objects are officially unordered, but the real world disagrees: signed payloads (JWS/webhooks) verify against exact bytes, golden test files diff line-by-line, and humans scan for fields where they last saw them. A formatter that sorts keys silently breaks all three. Sorting is a separate, deliberate operation — a different tool — never a side effect of pretty-printing.
The number-precision trap
JavaScript stores every number as a 64-bit float, exact for integers only up to 9007199254740991 (Number.MAX_SAFE_INTEGER). Database IDs, Twitter snowflakes and nanosecond timestamps routinely exceed it. A formatter built on plain JSON.parse rounds them — 9007199254740993 becomes …992 with no warning. This tool re-emits number tokens verbatim, so what you paste is what you get back.
Duplicate keys are legal-ish — and dangerous
This tool formats duplicates verbatim and warns you, naming both lines — it never picks a winner silently. The standards fine print and the security consequences are the JSON Validator page's deep dive.
Which indentation should you pick?
Two spaces is the ecosystem default — npm, Prettier and most style guides emit it, and it keeps deep structures readable without pushing them off-screen. Four spaces matches many enterprise Java and C# conventions. Tabs let every reader choose their own width and make the smallest diffs, but render inconsistently in web viewers. Compact is for machines: payloads, env vars, log lines. Whichever you pick, the bytes between tokens are the only thing that changes.
What the gzip figure tells you
Formatted JSON looks much bigger than minified — the status line might show 4 KB growing to 9 KB. The gzip figure is the honest comparison: because indentation is highly repetitive, both versions compress to nearly the same size on the wire. If your payload travels over HTTP with compression enabled (almost everything does), pretty-printing costs far less than the raw sizes suggest.
Comments, trailing commas, single quotes
Those are JSON5 and JSONC features, not JSON. Config files that allow them (tsconfig.json, VS Code settings) are parsed by more forgiving readers. This page validates strict RFC 8259 — the error message names the dialect when it spots one, so you know the file isn't broken, it's just not plain JSON.
Common errors
Unexpected '}' at line 12, column 3 — probable cause: trailing comma after the last property.- JSON forbids a comma after the final property or element. Delete the comma before the closing bracket — or paste the payload into a JSON5-tolerant editor if it was never meant to be strict JSON.
Unexpected "'" at line 1, column 2 — probable cause: single-quoted strings are JSON5, not JSON; use double quotes.- Every string in JSON — keys and values — must use double quotes. Single quotes usually arrive from JavaScript object literals or Python dict dumps.
Unexpected end of input at line 1, column 6 — probable cause: the document is incomplete or truncated.- The parser ran out of characters mid-value: usually a clipped log line, a truncated API response, or a copy that missed the closing brace.
Unterminated string at line 1, column 7 — probable cause: missing closing quote.- A string opened but never closed — usually a quote character inside the value that should have been escaped as \", or a copy that cut off mid-string.
Unexpected '{' at line 2, column 1 — probable cause: multiple JSON documents; this looks like NDJSON / JSON Lines.- One JSON document per file is the rule. Line-delimited JSON (NDJSON) is a different format in which every line is its own document — common in logs and LLM fine-tune datasets.
FAQ
Does this formatter change my data?
No. It re-emits your tokens with new whitespace and nothing else: key order, string escapes, and number digits all pass through byte-for-byte. Formatting then compacting returns exactly the input you started with, and our test suite proves that property on every build.
Why does my 19-digit ID come back unchanged here but rounded elsewhere?
Most formatters parse into JavaScript numbers, which are exact only up to 9007199254740991. Anything longer gets silently rounded to the nearest representable float. This tool never converts number tokens to floats — with “Preserve big numbers” on (the default), the digits you paste are the digits you get.
Is my JSON uploaded anywhere?
No. Formatting runs entirely in your browser — on large inputs, in a background worker thread on your machine. After the page loads, using this tool sends nothing over the network; you can verify that in your browser's network tab.
What is the difference between Compact and a JSON minifier?
The output is the same: every inter-token space removed. Compact is offered here because it is the inverse of formatting; the dedicated JSON Minifier page reports what the compaction actually saved, in raw bytes and gzipped weight.
Why won't it accept comments or trailing commas?
Because plain JSON (RFC 8259) forbids them. Files that allow comments are JSONC or JSON5 — different dialects with their own parsers. The error message names the dialect when it detects one, so you can tell a broken file from a mislabeled one.
How large an input can it handle?
Up to 50 MB. Inputs beyond about 256 KB format in a background worker so typing never freezes; beyond 2 MB the tool switches to an explicit Format button and shows the size it is about to process. Past 50 MB it refuses honestly and gives you the one-line CLI equivalent instead.