How to format and validate JSON
Paste JSON into the input. The formatter parses it and prints it back with consistent indentation, and the badge shows Valid or Invalid as you type. If the JSON doesn't parse, the error says what went wrong and where, so you can fix it without hunting through a long line.
Use Minify to strip all whitespace before you send a payload or store it. Whitespace between tokens has no meaning in JSON, so formatting and minifying never change the data itself.
Common JSON errors and how to fix them
- Trailing comma:
[1, 2, 3,]or{"a": 1,}. JSON allows no comma after the last item. Delete it. - Single quotes:
{'name': 'Ada'}. Strings and keys must use double quotes. - Unquoted keys:
{name: "Ada"}is valid JavaScript but not JSON. Quote every key. - Comments:
// noteor/* note */aren't allowed in standard JSON. Files liketsconfig.jsonaccept them because their tools use a looser format (JSONC); a strict parser rejects them. - JavaScript-only values:
undefined,NaN,Infinityand functions have no JSON form. Usenullor a string instead. - Missing comma between items, often after copying from a log:
{"a": 1 "b": 2}.
Example
This input has three errors: single quotes, an unquoted key and a trailing comma.
{'name': 'Ada', tags: ['math',],}
// Fixed:
{
"name": "Ada",
"tags": ["math"]
}Large numbers and precision
The formatter reads numbers the way JavaScript does, as 64-bit floating point. Integers above 9,007,199,254,740,991 can't be stored exactly and come back slightly changed. If an API sends large IDs, it should send them as strings; most large public APIs do this for exactly this reason.
When to use related tools
To see what changed between two JSON documents regardless of key order, use JSON Compare. To get a spreadsheet, use JSON to CSV. To generate types for your code, use JSON to TypeScript.