Home โบ JSON Formatter & Validator
JSON Formatter & Validator
How this JSON formatter works
When you click Format, the text is parsed with the browser's native JSON.parse, which follows the strict JSON grammar from RFC 8259. If parsing succeeds, the resulting value is serialized again with JSON.stringify using the indentation you picked. Minify does the same with no indentation at all. Because the data is round-tripped through a real parser, the output is guaranteed to be valid JSON โ this is not a regex-based "beautifier".
If parsing fails, the tool converts the parser's error position into a line and column number and shows the offending line with a caret under the problem character, so you do not have to count characters in a 3,000-line log dump.
Common JSON errors and how to fix them
| Invalid | Valid | Why |
|---|---|---|
{"a": 1,} | {"a": 1} | Trailing commas are not allowed. |
{'a': 'x'} | {"a": "x"} | Strings and keys need double quotes. |
{a: 1} | {"a": 1} | Keys must be quoted strings. |
{"n": NaN} | {"n": null} | NaN, Infinity and undefined do not exist in JSON. |
{"n": 012} | {"n": 12} | Leading zeros are not allowed in numbers. |
Another frequent trap is a raw line break or tab inside a string. JSON strings must escape control characters, so a multi-line value has to be written as "line1\nline2".
Gotchas worth knowing
- Big integers: values above 253โ1 are rounded by JavaScript (for example
12345678901234567890becomes12345678901234567000). Twitter/X and many databases send 64-bit IDs as strings for this reason. - Duplicate keys: JSON technically allows them, but the parser keeps only the last value. If formatting "loses" a field, check for duplicates.
- Sort keys sorts object keys alphabetically at every level, which is handy before diffing two API responses. Array order is never changed.
- JSON Lines / NDJSON (one JSON object per line) is not a single JSON document. Format each line separately.
Frequently asked questions
Is it safe to paste JSON with API keys or customer data here?
Yes. The formatter uses your browser's built-in JSON.parse and JSON.stringify. The page makes no network request with your input, so the data never leaves your device. You can even load the page, disconnect from the internet and keep using it.
Why does my JSON fail with 'Unexpected token' when it looks fine?
The most common causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, comments (// or /* */) and special values such as NaN, Infinity or undefined. All of these are valid JavaScript but not valid JSON (RFC 8259).
Does formatting change my numbers?
Numbers are parsed into JavaScript doubles, so integers larger than 9007199254740991 (2^53 - 1) lose precision, and 1.0 becomes 1. If you work with 64-bit IDs, keep them as strings in your JSON.
What is the difference between formatting and minifying JSON?
Formatting (pretty-printing) adds line breaks and indentation so humans can read it. Minifying removes all insignificant whitespace to make the payload smaller for transport. Both produce exactly the same data.