JSON Formatter & Viewer
Pretty-print, validate, and explore JSON as a tree. All in your browser.
What is JSON Formatter & Viewer?
JSON Formatter & Viewer pretty-prints, validates, and minifies JSON right in your browser. Paste messy JSON to format it online with 2-space indentation, catch syntax errors with line and column hints, or sort keys alphabetically for easy diffing — all for free, with nothing sent to a server.
Key features
- Format with 2-space indentation or minify to one line
- Sort keys recursively for deterministic, diff-friendly output
- Clear error messages with line and column when available
- Summary of total key count and nesting depth for valid JSON
- Side-by-side input and output panels with one-click copy
How to format, validate and minify JSON
Most JSON arrives unreadable: an API response printed on one line, a config file with inconsistent spacing, a log entry you need to eyeball fast. This tool cleans it up, tells you whether it's actually valid, and transforms it — all in your browser's own JavaScript engine, so even a payload full of tokens or customer data never leaves your device.
The three actions
- Format pretty-prints with 2-space indentation, turning a wall of text into a readable tree.
- Minify strips every optional space and newline into one compact line — the form you want for shipping JSON over the wire or embedding it.
- Sort keys recursively alphabetizes the keys of every object, top to bottom.
Validation you can act on
Paste something broken and you get a clear error message, plus the line and column of the problem when your browser reports it — enough to jump straight to the stray comma or unclosed brace. When the document is valid, you get a summary showing the total key count and nesting depth, a quick sanity check that a deeply nested structure is shaped the way you expect.
The sort-keys workflow
Sorting keys is the underrated feature. Two JSON objects with the same data but keys in different orders look completely different to a line-based diff tool. Run Sort keys on both first and the ordering noise disappears, so a git diff or side-by-side compare shows only the values that genuinely changed. It's the fastest way to answer "what actually differs between these two API responses?"
Common gotchas
JSON is stricter than the JavaScript object literal it resembles, and these are the mistakes that trip people up:
- No comments.
//and/* */are invalid JSON and will fail to parse. - No trailing commas. A comma after the last item in an array or object is a syntax error.
- Keys must use double quotes.
{'a': 1}and{a: 1}are both invalid; only{"a": 1}parses. - Duplicate keys silently lose data. If an object has the same key twice, the parser keeps only the last one, so the formatted output will be missing the earlier value.
- Very large numbers lose precision. Integers beyond about 9 quadrillion (2⁵³) can't be represented exactly, so re-formatting may change the last digits. Keep such IDs as strings.
One thing it won't do is repair broken JSON — it reports the first error and where it is, but fixing the stray comma or quote is up to you. Once the document parses cleanly, the nesting-depth figure in the summary is a fast way to catch accidental over-nesting, like an array wrapped one level deeper than your code expects.
Because everything runs locally, it's safe to paste sensitive payloads — nothing is transmitted, logged, or seen by anyone but you.
Frequently asked questions
- Why does my JSON fail to validate when it looks fine?
- JSON is stricter than a JavaScript object: comments, trailing commas, and single-quoted or unquoted keys are all invalid. The most common culprits are a comma after the last item in an array or object, or keys written without double quotes. When your browser reports it, the error message includes the exact line and column so you can jump straight to it.
- How does sorting keys help with diffing?
- Two objects with the same data but keys in a different order look completely different to a line-based diff. Running Sort keys on both first removes that ordering noise, so a git diff or side-by-side compare shows only the values that genuinely changed. It's the fastest way to answer what actually differs between two API responses.
- Is it safe to paste sensitive data like API tokens?
- Yes. Parsing, formatting, validation, and minifying all happen in your browser's own JavaScript engine, and nothing is transmitted, logged, or stored on a server. The payload never leaves your device, so pasting production data or secrets carries no upload risk.
- What happens to an object with duplicate keys?
- The parser keeps only the last occurrence, so the formatted output silently drops the earlier value. If you were expecting both, that's a data-loss gotcha to watch for. Deduplicate or rename the keys in your source before relying on the result.
- Why did a large ID number change after formatting?
- JavaScript can't represent integers beyond about 9 quadrillion (2 to the 53rd) exactly, so very large numeric IDs can lose their last digits when parsed and re-printed. Store such IDs as strings in your JSON to keep them intact. Values within the safe range are unaffected.
Privacy
Parsing, formatting, and validation all happen in your browser's own JavaScript engine — the JSON you paste is never transmitted anywhere, even to Spellkit's own servers.
