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.

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).
  2. Choose an indentation style — 2 spaces is the community default, tabs and 4 spaces 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, and a collapsible tree 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. Use Minify when you need the opposite direction — one compact line for embedding in a request or a config value — and Copy result to take the output with you.

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.

Related tools

Related guides