What this JSON formatter and validator does
Paste JSON from an API response, a log line or a config file and the tool checks it against the JSON standard. If it is valid, you get it back pretty printed with 2 spaces, 4 spaces or tabs, minified to a single line, or with every object's keys sorted. If it is not valid, you get the line and column of the first problem, the offending line with a caret under the spot, and a plain description of what is wrong.
How to use it
- Paste JSON into the box. Validation starts as you type.
- Choose the output style.
- If the input is invalid, fix the reported spot and the result refreshes.
- Copy the formatted JSON or download it as formatted.json.
JSON syntax rules that catch people out
JSON (RFC 8259) is stricter than JavaScript object syntax. These are the errors the validator recognizes and explains:
| Invalid | Valid | Rule |
|---|---|---|
{"a": 1,} | {"a": 1} | No trailing commas |
{'a': 'x'} | {"a": "x"} | Only double quotes |
{a: 1} | {"a": 1} | Keys must be quoted strings |
{"n": .5} | {"n": 0.5} | Numbers start with a digit or minus |
{"n": 007} | {"n": 7} | No leading zeros |
{"v": NaN} | {"v": null} | No NaN, Infinity or undefined |
// note | (remove it) | No comments |
| a raw tab or line break in a string | "a\tb", "a\nb" | Control characters must be escaped |
Other things the validator reports: a missing comma between two items, an unclosed string, a missing closing bracket, curly quotes pasted from a word processor, invalid escapes such as \x, and extra text after the end of the value. A document has exactly one top-level value, which may be an object, an array, a string, a number, true, false or null.
What the formatter does not change
Formatting changes only the whitespace between tokens. Spaces inside strings are kept, the order of array items is kept, and unless you choose Sort keys, the order of keys is kept too. Two things can change because of how JavaScript reads JSON: a repeated key keeps only its last value, and integers larger than 9,007,199,254,740,991 lose precision. The tool warns about the second case.
Worked examples
A trailing comma
Input {"a":1,} reports: Invalid JSON at line 1, column 8: Trailing comma: remove the comma before }. Column 8 is the closing brace that follows the comma.
A broken multi-line config
In {"a":1, followed by a second line "b":tru}, the error points to line 2, column 7, where the unquoted word tru starts. Only true, false and null may appear without quotes.
An ID that changes
{"id": 12345678901234567890} is valid, but the formatted output reads 12345678901234567000. The warning explains that the integer exceeded the safe range. This is why some APIs, Twitter's among them, also send large IDs as strings.
Tips and common mistakes
- Fix the first error first. One missing quote can make everything after it look wrong. Recheck after each fix.
- JSONC and JSON5 are different formats. Files such as tsconfig.json allow comments and trailing commas because their tools use a relaxed parser. Standard JSON parsers reject them.
- Watch copied text. Chat apps and word processors replace straight quotes with curly ones, which JSON does not accept.
- Minify for transport, pretty print for people. Minified JSON is smaller to send; indented JSON is far easier to read and to compare in version control.
Limits and privacy
Input up to 10 MB is accepted. Extremely deep nesting, thousands of levels, may exceed the browser's limits and is reported as an error instead of freezing the page. The validator stops at the first error. Your JSON, including any tokens or personal data inside it, is processed in the browser and never sent anywhere.