JSON Formatter & Validator

Format, validate and inspect JSON in your browser, with precise error locations and a collapsible tree view. Free, no sign-up — runs locally in your browser.

Your work is auto-saved in this browser only, so a refresh won't lose it. Nothing is uploaded.

…or drop a file onto the box above. Files are read locally, never uploaded.

What is a JSON formatter?

JSON (JavaScript Object Notation) is the data format the modern web runs on: APIs return it, configuration files are written in it, logs are emitted as it. But JSON that comes out of a machine is usually optimised for machines — a single line with no spaces, thousands of characters long. A JSON formatter takes that dense string and rewrites it with line breaks and indentation so a human can actually read the structure: nested objects open and close on their own lines, arrays list one element per line, and the shape of the data becomes visible at a glance.

A formatter that also validates — like this one — does something just as important before it formats: it checks that the document is really JSON. Most "formatting" failures are not formatting problems at all; the input is broken JSON, and a good tool tells you exactly where, instead of showing a blank page or a vague "invalid input" complaint.

How to use this tool

  1. Paste your JSON into the box above (or press Load sample to see a worked example). You can also upload a .json file or drop one onto the box — the file is read in your browser and never sent anywhere.
  2. Choose an indentation style — 2 spaces is the community default; 3 spaces, 4 spaces and tabs are one click away — and tick Sort keys if you want object members alphabetised, which is handy when diffing two payloads.
  3. Press Format. If the JSON is valid you get the formatted document, some quick statistics, a collapsible tree view and a graph view for exploring deep structures. If it is not valid, you get the precise line and column of the first error, with the offending line quoted.
  4. Tick Auto-format as I type if you would rather not press the button at all: the result updates as you edit (very large inputs are still formatted on demand, to keep typing smooth).
  5. Use Minify when you need the opposite direction — one compact line for embedding in a request or a config value — then Copy result, Download result or Print result to take the output with you.

Repairing broken JSON — with the receipts

Sometimes you do not get to choose your input: a hand-edited config with single quotes and a trailing comma, a truncated log line, a snippet copied out of Python with True and None in it. Repair broken JSON runs a tolerant repair pass (the open-source jsonrepair library) over text like that and produces the closest valid JSON.

Repairs here are never silent, because a repair is a guess about what you meant. Your original text is left untouched; the repaired document appears as the result, under a banner that says it was repaired and lists what the repair changed — comments removed, quotes added, trailing commas dropped, brackets closed — plus a line-by-line difference count so you can judge how far the guess went. Only if you press Replace my input does the repaired version become your input. If a repair would have to invent data rather than fix syntax, the tool refuses and changes nothing.

Tree view and graph view

The tree view renders the document as collapsible branches — good for reading deep nesting in order, and for spotting the one field that is the wrong type. String values that are image URLs get a dotted underline; hovering one previews the image (the image is fetched only at that moment, directly from its own host). The graph view draws the same structure as a node-and-line diagram you can pan and zoom, with branches you can collapse and expand — better than the tree when you want the shape of the whole document at once. To keep your browser responsive, the graph draws at most 400 nodes; when a document is larger, the graph is partial and says so, with the full node count shown.

How JSON validation works

Validation is parsing: the tool feeds your text to a strict JSON parser that follows the grammar defined by RFC 8259 and ECMA-404. The grammar is small and unforgiving. A JSON value is an object, array, string, number, or one of the three literals true, false, null. Strings must be double-quoted. Object keys must be strings. Numbers may not have leading zeros or a bare decimal point. There are no comments, no single quotes, no trailing commas, and no unquoted keys — most of the "JSON" people write by hand breaks at least one of these rules, because it looks so much like JavaScript object syntax while being considerably stricter.

When parsing fails, the parser stops at the first character it cannot accept. This tool reports that position as a line and column and shows you the line, because the first error is the only one worth fixing: everything after it is usually a cascade. Fix the first error, format again, and repeat — real-world payloads typically surrender after two or three rounds.

Examples

This compact payload:

{"user":{"id":42,"name":"Ada"},"roles":["admin","editor"],"login_count":318}

formats into:

{
  "user": {
    "id": 42,
    "name": "Ada"
  },
  "roles": [
    "admin",
    "editor"
  ],
  "login_count": 318
}

And this broken input — note the missing quote and the trailing comma — is reported as an error at the exact line and column where parsing stops, instead of being silently "repaired" into something you did not write:

{
  "name": "Ada,
  "roles": ["admin",]
}

Common JSON mistakes

If you are deciding which format a file should be in at all, read our comparison of JSON vs YAML — the two formats look interchangeable from a distance and behave very differently up close.

Frequently asked questions

Is JSON case-sensitive?

Yes. Keys, string values and the literals true, false and null are all case-sensitive: "Name" and "name" are different keys, and True or FALSE are not valid JSON at all. Only whitespace between tokens is insignificant.

Why does this tool reject trailing commas?

Because JSON itself does. The JSON grammar has no trailing commas in objects or arrays — {"a": 1,} is invalid even though JavaScript and JSON5 allow it. Remove the comma after the last member and the document will parse.

Is my JSON uploaded anywhere?

No. Formatting and validation happen in your browser using the JSON parser built into it. Nothing is sent to a server — you can disconnect from the network and the tool keeps working.

What is the difference between formatting and validating?

Validation only answers "is this valid JSON, and if not, where does it break?" Formatting additionally rewrites a valid document with consistent indentation so you can read it. This tool always validates first; if the input is invalid you get the error location instead of formatted output.

Why do my large numbers lose precision?

JSON parsers in browsers turn every number into a 64-bit floating-point value, so integers above 2^53 (9007199254740991) can lose exactness — 9223372036854775807 comes back as 9223372036854775808. If you exchange 64-bit IDs, send them as strings.

Can I format JSON with comments?

Not as JSON — comments are not part of the format, so a document containing // or /* */ comments is invalid JSON and this tool will point at the comment as the error. The comment-tolerant variants are called JSONC or JSON5 and need a different parser. If you just need the data out of a commented document, the Repair broken JSON button can strip the comments — it will tell you that it did.

What exactly does 'Repair broken JSON' change?

It fixes syntax, never data: missing or single quotes are made double quotes, trailing commas are removed, comments are stripped, missing closing brackets are added, and Python-style True/False/None become true/false/null. Every repair is announced in a banner listing the changes, your original input is not modified unless you choose to replace it, and the repaired output should always be checked — a repair is a best-effort guess at what you meant.

Can I open a .json file instead of pasting?

Yes — use the Upload button or drag a file onto the input box. The file is read locally by your browser (it is never uploaded to a server), its contents land in the input box, and formatting runs immediately. Download result and Print result do the same job in the other direction.

Why does the graph view say it is partial?

The graph draws at most 400 nodes so that a huge document cannot freeze your browser. When a document has more nodes than that, the graph shows the first 400 and states the full count. The tree view and the formatted result always show the complete document.

Related tools

Related guides