belun.app

JSON Formatter, Validator & Fixer Online

Output
    

Valid JSON keeps six rules. Keys and strings in double quotes ("name", not 'name'). No comma after the last item. No comments. Only true, false and null, in lowercase. Numbers without leading zeros, NaN or Infinity. One value at the top.

Break one and the formatter names the rule with the line and column. Fix JSON repairs all six.

12 common errors and their fixes ↓ · indent vs file size ↓ · why big numbers break ↓

Paste JSON or open a .json file. It is checked as you type: valid input is pretty-printed straight away with 2, 3 or 4 spaces or tabs, invalid input gets the line, the column and a plain-English reason. Fix JSON turns JavaScript object literals, Python dicts, commented configs and cut-off API responses into valid JSON and lists every change. Tree view folds large documents and shows the JSONPath of any value.

Your JSON is parsed locally in your browser and never sent to a server.

12 common JSON errors and how they are fixed

Each row is run through the formatter when this page is built: the message and position are what the tool shows for that input, and the last column is what Fix JSON returns. Most come from pasting a JavaScript object, a Python dict or a config file with comments.

Broken JSON Line:col What the formatter says After Fix JSON
{"name": "Ann", "age": 30,} 1:26 Trailing comma: JSON allows no comma after the last item. Delete it. {"name":"Ann","age":30}
{'name': 'Ann'} 1:2 Single quotes are not JSON: put strings and keys in double quotes. {"name":"Ann"}
{name: "Ann"} 1:2 The property name name is not in double quotes: write "name". {"name":"Ann"}
{"a": 1 "b": 2} 1:9 Missing comma before "b". {"a":1,"b":2}
{"ok": True, "boss": None} 1:8 True is not JSON: write true in lowercase. {"ok":true,"boss":null}
{"ratio": NaN} 1:11 NaN is not allowed in JSON: use null or a string. {"ratio":null}
{"port": 8080} // dev 1:16 Comments (// and /* */) are not allowed in JSON. {"port":8080}
{"zip": 01234} 1:9 01234 is not a valid JSON number: no leading zeros, plus sign, hex or bare decimal point. {"zip":1234}
{"note": "line 1 line 2"} 1:17 A raw U+000A inside a string must be escaped (\n for a line break, \t for a tab). {"note":"line 1\nline 2"}
{"tags": ["a", "b"} 1:19 } does not close the open bracket: expected ]. {"tags":["a","b"]}
{"user": {"id": 1} 1:19 The JSON ends too early: close it with }. {"user":{"id":1}}
{“name”: “Ann”} 1:2 Curly quote “: JSON needs straight double quotes ("). {"name":"Ann"}

Indentation and file size

The same small API response, laid out four ways by the formatter. Minified it takes 59 bytes, 45% less than with 4-space indentation (107 bytes); the share grows with nesting, because every level adds indentation to every line below it. Over HTTP with gzip or Brotli most of that difference disappears, so minify for storage and URLs, and keep indentation for anything a person reads.

2 spaces · 89 bytes
{
  "id": 7,
  "name": "Ann",
  "roles": [
    "admin",
    "dev"
  ],
  "active": true
}
4 spaces · 107 bytes
{
    "id": 7,
    "name": "Ann",
    "roles": [
        "admin",
        "dev"
    ],
    "active": true
}
Tab · 80 bytes
{
	"id": 7,
	"name": "Ann",
	"roles": [
		"admin",
		"dev"
	],
	"active": true
}
Minified · 59 bytes
{"id":7,"name":"Ann","roles":["admin","dev"],"active":true}

Why some formatters change big numbers

A JavaScript number is a 64-bit float: integers are exact only up to 253 − 1 = 9,007,199,254,740,991. A formatter that parses the text and prints it back rounds anything longer, which silently corrupts 64-bit database ids and Twitter-style snowflake ids.

Input
{"id": 12345678901234567890}
JSON.parse + stringify
{"id":12345678901234567000}
This formatter
{"id":12345678901234567890}

How it works

  1. 1
    Paste or open your JSON Paste into the input, drop a .json file on it, or use Open file. The status line says at once whether the JSON is valid.
  2. 2
    Read the error or press Fix JSON An error shows its line and column, the line itself with a caret, and what to change. Go to error selects the spot in the input. Fix JSON repairs the usual mistakes and lists what it changed.
  3. 3
    Choose the layout Pick 2, 3 or 4 spaces or tabs, tick Sort keys to order every object A to Z, or press Minify for one compact line. Switch to Tree to fold and unfold nested objects.
  4. 4
    Copy or download Copy puts the output on the clipboard; Download saves it as a .json file named after the file you opened.

Frequently asked questions

How do I fix invalid JSON?
Press Fix JSON. It removes comments, trailing and doubled commas; turns single and curly quotes into double quotes; quotes bare keys and text; changes True, False and None to true, false and null and NaN or undefined to null; repairs numbers like +1, .5 and 007; closes brackets and strings left open by a cut-off response; and strips a ``` code fence or JSONP wrapper. Every change is listed, and Restore original brings your text back.
Does formatting change my numbers or key order?
No. The formatter re-indents the text token by token, so 12345678901234567890 stays 12345678901234567890, 1.0 stays 1.0, and duplicate keys keep their order. A formatter that runs JSON.parse and JSON.stringify returns 12345678901234567000 for that id, because JavaScript numbers hold about 15 to 17 significant digits. Keys move only when you tick Sort keys.
How do I format JSON in VS Code or a terminal?
In VS Code open the file and press Shift+Alt+F on Windows, Shift+Option+F on macOS or Ctrl+Shift+I on Linux. On the command line, python -m json.tool file.json pretty-prints with 4 spaces and jq . file.json with 2. Both stop at the first error with a short message; paste the file here to see the reason and repair it.
How large a file can it handle?
There is no fixed limit: a 10 MB file takes a second or two to format on a recent laptop. Input over 500,000 characters and output over 200,000 are shown one part at a time, while Copy and Download take all of it; after editing input that long, press Format. The tree view draws 200 children at a time. Nesting deeper than about 8,000 levels is shown minified.

Related tools