How to format JSON
- Paste your JSON, drop a
.jsonfile onto the editor or load it from a URL. - Click Format (or press Ctrl+Enter) and choose 2 spaces, 4 spaces or tabs. Minify removes all whitespace and Sort keys orders the properties alphabetically.
- If the JSON is invalid, the error box shows the line, the column and the cause, and the line is highlighted. Repair fixes trailing commas, comments, quotes and similar mistakes automatically.
A JSON formatter that keeps your data intact
Many online formatters run your data through JSON.parse and JSON.stringify, which silently changes it: large integers such as 12345678901234567890 are rounded, 1.50 becomes 1.5 and numeric keys like "10" jump to the top of an object. This JSON formatter only changes whitespace, so every number, escape sequence and key stays exactly as you wrote it.
- Format (beautify) – indent with 2 spaces, 4 spaces or tabs.
- Minify – remove all whitespace for the smallest payload.
- Sort keys – order object keys alphabetically at every level, handy before comparing two files.
- Validate – a strict JSON parser reports the exact line and column of the first error.
- Statistics – size, number of keys, objects, arrays and the nesting depth.
What Repair fixes
JSON copied from JavaScript code, Python, logs or AI chat answers is often almost valid. Repair turns it into strict JSON:
| Problem | Before | After |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Comments | // note, /* … */ | removed |
| Single quotes | {'a': 'b'} | {"a": "b"} |
| Unquoted keys | {a: 1} | {"a": 1} |
| Python values | True, False, None | true, false, null |
| NaN, Infinity, undefined | {"x": NaN} | {"x": null} |
| Missing commas | [1 2 3] | [1, 2, 3] |
| Unclosed brackets | {"a": [1, 2 | {"a": [1, 2]} |
| Several values (JSON Lines) | {"a":1} {"a":2} | [{"a":1}, {"a":2}] |
Format JSON in code and on the command line
- JavaScript:
JSON.stringify(data, null, 2) - Python:
json.dumps(data, indent=2), orpython -m json.tool file.jsonin a terminal - jq:
jq . file.jsonto format,jq -c .to minify andjq -S .to sort keys - PHP:
json_encode($data, JSON_PRETTY_PRINT)
Note that these all re-encode the data, so very large numbers may be rounded – unlike the formatter on this page.
Why use JSON Format Online?
- FreeEvery tool is free with no limits, accounts or watermarks.
- PrivateProcessing happens locally in your browser. Files are never uploaded.
- FastLightweight pages that load instantly on any device.
- Works everywhereUse it on Windows, macOS, Linux, Android and iPhone.
Frequently asked questions
Is my JSON uploaded to a server?
No. Formatting, validation and repair run entirely in your browser. Only Load URL fetches the file through our server, because browsers block most direct downloads from other sites; the content is passed straight to you and not stored.
Why does my JSON fail with “Unexpected token”?
JSON is stricter than JavaScript: keys and strings need double quotes, trailing commas and comments are not allowed, and values like NaN or undefined do not exist. The validator names the exact problem and position, and Repair fixes most of these mistakes automatically.
Does formatting change my numbers or key order?
No. Big integers, trailing zeros, escape sequences and the order of keys are kept exactly. Only Sort keys reorders properties, and even then every number keeps its original digits.
How large can the JSON be?
Files of tens of megabytes work in a modern desktop browser. The editor draws line numbers only for the visible lines, so long documents stay fast, and errors are reported even deep inside large files.