JSON (JavaScript Object Notation) is the most common data interchange format on the web. But raw JSON from APIs is often minified — no whitespace, no line breaks — making it nearly impossible to read. A JSON formatter adds indentation and line breaks to make the structure visible.
What is JSON?
JSON is a lightweight text format for representing structured data as key-value pairs, arrays, and nested objects. Every modern API, configuration file, and database export uses JSON.
{"name":"Alice","age":30,"roles":["admin","editor"]}
Formatted, this becomes:
{
"name": "Alice",
"age": 30,
"roles": [
"admin",
"editor"
]
}
Common JSON errors
| Error | Cause |
|---|---|
| Unexpected token | Trailing comma, missing quote |
| Unexpected end of JSON | Unclosed bracket or brace |
| Property names must be strings | Using single quotes instead of double |
| Invalid escape character | \n instead of \\n in strings |
How to format JSON online
- Go to JSON Formatter
- Paste your JSON into the input panel
- The formatted output appears instantly in the right panel
- Use Minify to compress it back for production use
JSON vs JavaScript object literals
JSON is stricter than JavaScript:
- All property names must be double-quoted strings
- No trailing commas allowed
- No comments allowed (
//or/* */) - No
undefined,function, orDatevalues (use strings for dates)
Validating API responses
When debugging API calls, paste the raw response body into the formatter. If there's a syntax error, the tool will highlight the line and describe the problem. This is faster than reading error stack traces in code.
Minifying JSON for production
Minified JSON removes all whitespace, reducing file size by 20–40%. Use minify mode when embedding JSON in code, configuration files shipped with apps, or API responses where bandwidth matters.
One caveat: if the response is served with gzip or brotli — which almost all are — the real-world saving is much smaller, because compression already handles repeated whitespace efficiently. Minify for embedding and storage; do not expect a dramatic transfer-size win on a compressed endpoint.
Reading the error message
Most parsers report a character offset rather than a line, which is useless on one long minified line. The message follows a pattern worth learning:
| Message | Almost always means |
|---|---|
Unexpected token } in JSON at position N |
Trailing comma just before the } |
Unexpected end of JSON input |
Truncated response — check for a timeout or size limit |
Unexpected token < in JSON at position 0 |
Not JSON at all — an HTML error page |
Unexpected token ' in JSON |
Single quotes; JSON requires double |
Unexpected non-whitespace character after JSON |
Two objects concatenated, or JSON Lines |
That third row is the one people lose the most time to. A < at position 0 means the server returned HTML — a 500 page, a login redirect, or a proxy error — and the JSON parser is simply the first thing to notice. Check the HTTP status before debugging the parser.
Numbers: the silent data-loss bug
JSON numbers are arbitrary precision in the spec, but JSON.parse maps them to IEEE-754 doubles. Any integer beyond 2^53 loses precision silently:
JSON.parse('{"id": 9007199254740993}').id
// -> 9007199254740992 (off by one, no error)
This bites on 64-bit database IDs, Twitter/X snowflake IDs, and financial values in minor units. The fix is server-side: serialise large IDs as strings. Once precision is lost in the parse, it cannot be recovered.
For the same reason, avoid floats for money. 0.1 + 0.2 is 0.30000000000000004 in JSON as in any IEEE-754 language. Store integer cents.
Duplicate keys
JSON permits duplicate keys; the spec does not say which wins. In practice most parsers take the last:
{"role": "user", "role": "admin"}
Different parsers on different tiers of a system can disagree, which has been used to smuggle values past validation. If a payload has duplicate keys, treat it as suspect rather than merely untidy.
JSON vs JSONL vs JSON5
- JSON — one value per document. What APIs return.
- JSON Lines (
.jsonl) — one complete JSON object per line, no wrapping array. Built for streaming and log files; a standard parser rejects the file as a whole, which is theUnexpected non-whitespace charactererror above. - JSON5 — a superset allowing comments, trailing commas, and unquoted keys. Convenient for config files, but it is not JSON and standard parsers reject it.
Frequently asked questions
Is it safe to paste API responses into an online formatter?
Only if it runs in your browser. API responses routinely contain tokens, emails, and internal IDs. This formatter processes everything client-side — nothing is uploaded — but always check before pasting production data into any tool.
How do I add comments to JSON?
You cannot; the spec has no comments. Common workarounds are a "_comment" key, or switching the file to JSON5 or YAML if it is a config rather than an API payload.
What indentation should I use?
Two spaces is the most common convention and what most formatters default to. Tabs are valid. The only rule that matters is consistency within a repository.
Why does my JSON have \uXXXX-style escapes?
Non-ASCII characters may be escaped as \uXXXX for transport safety. They decode to the correct characters; the escaped form is valid and equivalent.
Can JSON store dates?
Not natively — there is no date type. The convention is an ISO 8601 string ("2026-08-20T03:16:08Z"), which sorts correctly as text and parses unambiguously.
What is the maximum size a JSON file can be?
The format has no limit, but parsers do — JSON.parse loads the whole document into memory. For very large datasets, use JSON Lines and process it row by row.