Minified JSON from an API response is effectively unreadable — one line, no whitespace, thousands of characters. Formatting it with consistent indentation turns it into something you can actually navigate, and validating it tells you precisely where a malformed payload breaks.
How to use the JSON Formatter
- Paste your JSON into the input box
- Click Format to beautify it, or Minify to strip whitespace
- If the JSON is invalid, read the error — it names the position of the problem
- Copy the result, or switch tabs to compare two documents
The JSON syntax rules people trip over
Almost every parse error comes from one of four things:
- Trailing commas.
{"a": 1,}is valid JavaScript and invalid JSON. This is the single most common error. - Single quotes. JSON requires double quotes for both keys and string values.
{'a': 1}is not JSON. - Unquoted keys.
{a: 1}is a JavaScript object literal, not JSON. - Comments. JSON has none.
//and/* */both cause a parse failure.
JSON also has no date type — dates are strings by convention, usually ISO 8601 — and no trailing-comma tolerance regardless of which parser you use.
Formatting versus minifying
Format adds indentation and line breaks so humans can read the structure. Use it while debugging, and in files people edit by hand such as package.json or config.
Minify strips every optional byte of whitespace. Use it for anything transmitted over a network or stored at volume — on a large payload it routinely saves 15–30%, and the parser does not care either way.
Whitespace carries no meaning in JSON, so the two forms are exactly equivalent to any parser. The choice is purely about whether a human or a wire is the consumer.
Reading a parse error
Parsers report the position where parsing became impossible, which is usually a little past where the mistake is. A missing closing brace is only detected at the end of the file, so an error on line 400 can mean a problem on line 12.
A few messages translate reliably:
- "Unexpected token }" — almost always a trailing comma before that brace.
- "Unexpected end of JSON input" — the document is truncated, or a bracket is never closed. Check the response was complete before blaming the content.
- "Unexpected token ' in JSON" — single quotes where double quotes are required.
- "Unexpected non-whitespace character after JSON" — two JSON documents concatenated, which happens when an API appends a debug line or a PHP warning gets printed before the payload.
When the reported position looks arbitrary, work backwards from it to the nearest opening bracket. The structure between that bracket and the error is where the problem is.
Numbers, precision and the things JSON cannot hold
JSON's number type has no precision specified, and in practice every JavaScript parser reads numbers as IEEE 754 doubles. That is exact up to 2^53 — about 9 quadrillion — and silently lossy beyond it.
This matters more than it sounds, because large integer identifiers are common. A 64-bit database id or a Twitter-style snowflake id exceeds the safe range, and parsing it rounds the last few digits. The value looks plausible, matches nothing, and the bug surfaces far from its cause. The standard fix is to transmit such ids as strings, which is why many APIs return "id": "1234567890123456789" with quotes that look unnecessary.
Decimals have the familiar floating-point behaviour too: 0.1 + 0.2 is not 0.3. Money should be an integer count of the smallest unit, or a string, never a float.
JSON also has no date type, no comments, no trailing commas, and no NaN or Infinity. Dates are strings by convention, normally ISO 8601, and that convention is worth following because it sorts correctly as text.
Frequently asked questions
Is my JSON sent to a server?
No. Parsing and formatting happen entirely in your browser. This matters because API responses routinely contain tokens, personal data and internal identifiers.
Why does my JSON fail to parse when it looks correct?
Check for a trailing comma after the last item, single quotes instead of double, unquoted keys, or comments. Those four account for the large majority of parse failures.
What indentation should I use?
Two spaces is the most common convention and what most formatters default to. Four is also widely used. Tabs are valid JSON but unusual in practice.
Does formatting change my data?
No. Only whitespace changes. Keys, values, types and ordering are all preserved exactly.
Can it handle very large files?
Up to a few megabytes comfortably. Beyond that the browser will slow noticeably, since the entire document is parsed into memory at once.