Validation and pretty-printing, explained properly
A JSON formatter is a parser front-end: it reads your text with a strict JSON parser, rejects it with a position-tagged error if the syntax is invalid, and re-serialises the parsed structure with consistent indentation.
The useful part of a JSON formatter is not the indentation — it is the parse step in front of it. When an API returns 400, when a CI job fails on a config file, or when a webhook payload silently drops a field, the question is almost always whether the document is valid JSON and, if not, exactly which character broke it.
This page covers what the parser accepts and rejects, the four syntax errors that account for most failures, how beautifying and minifying differ mechanically, and when a browser tool is the wrong choice.
What each button does under the hood
Both actions run the same parse first. If the parse fails, nothing is produced — that is the validation.
- Format
- Parses the text, then re-serialises it with two-space indentation. Because it round-trips through a parser, the output is guaranteed to be valid JSON and key order is preserved as written.
- Minify
- Parses the text and re-serialises with no whitespace at all. Typical saving on an indented API response is 15–30% of the byte count before any compression.
- The tree view
- Valid output renders as a collapsible tree with values coloured by type — strings, numbers, booleans and null are visually distinct — so a number that arrived as a quoted string is obvious at a glance.
- Error reporting
- The message comes from your browser’s own JSON parser and includes a character position. Wording differs between Chrome, Firefox and Safari; the position number is the part to trust.
- Where it runs
- Entirely in your browser. Payloads are never uploaded, which matters when a response body contains customer data or a bearer token.
- What is not valid JSON
- Comments, trailing commas, single-quoted strings, unquoted keys, NaN, Infinity and undefined. Several of those are legal JavaScript, which is why they slip in so often.
The four failures that cause most invalid JSON
Each example below is a real rejection. Read the position number, look at that character, and fix the first error only — later errors usually disappear with it.
Example 1: Trailing comma
{"name": "Ada", "role": "engineer",}Expected double-quoted property name
in JSON at position 35Position 35 is the closing brace. After a comma the parser requires another key, so it reports the brace, not the comma. JavaScript object literals allow the trailing comma; JSON never has.
Example 2: Single quotes
{'name': 'Ada'}Expected property name or '}'
in JSON at position 1JSON strings must use double quotes, for keys and values alike. This is the classic symptom of pasting a Python dict or a JavaScript literal and expecting it to parse.
Example 3: Comments in a config file
{
"port": 8080, // dev only
"debug": true
}Unexpected token '/'
… is not valid JSONStandard JSON has no comment syntax. Tools such as VS Code accept JSONC in their own settings files, but a strict parser — including this one and most server-side libraries — will not.
Example 4: A number that is really a string
{"total": "1200", "count": 3}{
"total": "1200", ← string
"count": 3 ← number
}This is valid JSON, so validation cannot help you. The colour-coded tree is how you catch it: a quoted "1200" will fail arithmetic downstream. Type mismatches cause more production bugs than syntax errors do.
Behaviour that surprises people
Duplicate keys are silently resolved
JSON.parse keeps the last occurrence of a repeated key, so {"a":1,"a":2} becomes {"a":2} with no warning. If your formatted output is missing a field you definitely pasted, look for a duplicate key above it.
Very large integers lose precision
JSON numbers are parsed as IEEE-754 doubles. An ID above 2^53 − 1 (9,007,199,254,740,991) will round — a real problem with Twitter-style snowflake IDs and some ledger systems. Transmit those as strings.
Key order is preserved, not sorted
Formatting re-serialises in insertion order. It will not normalise two payloads for diffing; use a dedicated JSON diff or sort keys in code if you need stable comparison.
Minify before you compress, not instead
Gzip and Brotli already collapse repeated whitespace efficiently. Minifying a response that is compressed in transit saves far less than the raw byte count suggests — it matters most for storage, log lines and URL-embedded payloads.
Secrets in pasted payloads
Nothing is uploaded, but screenshots are. Strip Authorization headers, API keys and personal data before sharing a formatted payload in a ticket. Need to inspect an encoded token first? Decode it with the Base64 encoder and decoder.
Browser formatter vs. jq, your IDE, and a browser extension
Direct answer: use a browser formatter for a one-off payload you already have in your clipboard, and a command-line tool the moment you need to filter, transform or script.
| Option | Best for | Trade-off |
|---|---|---|
| This browser formatter | A payload pasted from DevTools, a log line or a support ticket | No querying or transformation, and no file handling — it is a read-and-fix surface, not a pipeline stage. |
| jq on the command line | Filtering, reshaping and scripting over files or streams | A real query language to learn, and it is another dependency on a locked-down machine. |
| IDE formatting (VS Code, JetBrains) | JSON that lives in your repository | Formats on save with your project settings, but you have to get the payload into a file first. |
| Browser JSON-viewer extension | Reading API responses directly in a browser tab | Only helps for URLs you can open in a browser — no help with a POST body or a payload from a log. |
Working with tabular source data instead? Convert it first with the CSV to JSON converter, then format the result here.
A repeatable way to debug a rejected payload
- Fix the first reported error only, then re-run — cascading errors are usually one missing bracket.
- Compare the position number against the raw text, not the pretty-printed version, since indentation shifts offsets.
- If the document is truncated, check whether the source was cut by a log line-length limit before blaming the API.
- Confirm value types in the tree view: quoted numbers and "true" as a string are frequent culprits.
- For a schedule or automation payload, sanity-check the cron field with the cron expression parser.
- Need to pull specific values out of a large document? Prototype the pattern in the regex tester before writing the parsing code.
How this page is maintained
Error messages shown here were reproduced with the browser JSON parser this tool uses, and the two-space indentation and tree-view behaviour were read from the tool’s source. Parser wording varies by browser engine, which the page states rather than glossing over.
Written and reviewed by the ToolsRacks editorial team. Last reviewed: .