How to format JSON
- Paste your JSON into Input, open a .json file, or drop one on the box. It is formatted as you type.
- Pick an indent of 2 spaces, 4 spaces or tabs, and turn on Sort keys A–Z to order every object's keys alphabetically.
- Switch to Tree to fold objects and arrays and see how many keys or items each one holds.
- Copy the result or download it as formatted.json. Minify removes all whitespace for the smallest file.
Everything runs in your browser. Your JSON is never uploaded, so it is safe to format API responses, config files and tokens.
JSON validator: finding the error
If the JSON is invalid, the bar under the editor turns red and names the problem with its line and column, and the line itself is shown with the bad character highlighted. JSON is strict: one stray comma or a single quote breaks the whole document. The most common errors:
| Error | Example | Fix |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Delete the comma after the last item. |
| Single quotes | {'name': 'Ann'} | Use double quotes around keys and strings. |
| Unquoted key | {name: "Ann"} | Put the key in double quotes: "name". |
| Missing comma | {"a": 1 "b": 2} | Add a comma between items. |
| Comments | {"a": 1 // note} | JSON has no comments. Remove them. |
| Leading zero | {"zip": 02134} | Write it as a string, "02134", or drop the zero. |
| Python values | {"ok": True, "x": None} | Use true, false and null in lowercase. |
| NaN or Infinity | {"ratio": NaN} | JSON has no NaN. Use null or a string. |
| Line break in a string | {"text": "line one↵line two"} | Write the line break as \n. |
Repair fixes most of these automatically. It accepts single quotes, unquoted keys, trailing commas, comments and Python's True, False and None, then rewrites the input as valid JSON.
Beautify vs minify
Beautified JSON has line breaks and indentation so people can read it. Minified JSON strips every unneeded space and line break, which makes API payloads and files smaller. Both hold exactly the same data. A typical response shrinks by 20% to 40% when minified, more when it was deeply indented.
Escape and unescape JSON
Escape turns the input into a single JSON string, with quotes and line breaks escaped, so you can embed JSON inside another JSON value or a code string. Unescape does the reverse: paste a quoted string such as "{\"a\":1}" and it becomes formatted JSON again.
JSON rules in short
- Objects use
{ }with keys in double quotes; arrays use[ ]. - Values are strings in double quotes, numbers, true, false, null, objects or arrays.
- No trailing commas, no comments, no single quotes, no undefined.
- Strings escape quotes, backslashes and control characters:
\",\\,\n,\t,\u00e9.
JSON5 and JSONC, used by some config files such as tsconfig.json, allow comments and trailing commas. Repair converts them to standard JSON.