JSON Formatter, Validator & Minifier

Paste JSON to pretty-print it, minify it, or find the exact line and column of a syntax error. Explore nested data in a collapsible tree. Your data never leaves your browser.

How to use this JSON formatter

Paste your JSON into the input box on the left, or click Open file… to load a .json file from your computer. Then pick an action:

Switch to Tree view to browse the parsed data as collapsible branches. Each object shows how many keys it has and each array how many items, so you can find the part you care about without scrolling through thousands of lines. Hover over any node to see its path, such as $.address.city or $.roles[1], which you can reuse in JSONPath queries or in code.

The Sort keys A–Z option reorders object keys alphabetically at every level. It is useful when you want to compare two API responses or config files in a diff tool, because the same data will then always produce the same text.

What makes JSON invalid?

JSON looks like JavaScript, but its grammar (defined in RFC 8259) is much stricter. Almost every error people hit falls into a handful of categories, and the validator names them in plain English:

Click Try a broken sample to see how errors are reported. The status bar names the problem, the line number in the gutter turns red, and a context panel shows the surrounding lines with a caret under the exact character. Go to error moves your cursor there so you can fix it immediately.

Reading an error message correctly

A parser reports the place where it noticed the problem, which is not always where the mistake was made. If you forget a comma at the end of line 3, the error is usually reported at the start of line 4, because that is where the parser finds a second value it did not expect. When the message says “Expected “,” or “}” after object value”, look at the end of the previous line first. Similarly, an unterminated string is reported where the string started, since the parser cannot know where you meant it to end.

Formatting versus minifying: when to use which

Formatted JSON is for humans. Use it when reading API responses, reviewing configuration in pull requests, or writing documentation. Two-space indentation is the most common convention in JavaScript projects, while four spaces is typical in Python’s json.dumps(indent=4) output. Tabs keep files slightly smaller and let each reader choose their own visual width.

Minified JSON is for machines. Whitespace is meaningless to a parser, so stripping it reduces payload size, often by 10–30% for heavily nested data. If your server already uses gzip or Brotli compression, the saving on the wire is much smaller because whitespace compresses extremely well, so minification matters most where compression is not applied: local storage, query strings, message queues and logs.

Practical tips

A quick example

This minified response from an API is hard to read:

{"user":{"id":42,"tags":["beta","pro"],"plan":null}}

After formatting with two-space indentation it becomes:

{
  "user": {
    "id": 42,
    "tags": [
      "beta",
      "pro"
    ],
    "plan": null
  }
}

In the tree view the same document collapses to a single user branch with three keys, and hovering over "pro" shows its path, $.user.tags[1].

Your data stays on your device

API payloads often include access tokens, email addresses or internal hostnames, so pasting them into a website that uploads them is a real risk. JSON Lens parses and formats everything with JavaScript running in your browser tab. There is no server-side processing and nothing is saved, which also means the tool keeps working if you lose your connection after the page has loaded.

Frequently asked questions

Is my JSON uploaded to a server?

No. Formatting, validation, minification and the tree view all run in JavaScript inside your browser. The JSON you paste is never sent anywhere and is discarded when you close the tab.

Why does the error point to the line after my mistake?

A parser reports where it noticed the problem. A missing comma at the end of one line is detected when the next value starts, so check the end of the previous line as well as the reported position.

Can this tool fix invalid JSON automatically?

It does not silently rewrite your data, because guessing the intended structure can introduce subtle bugs. Instead it pinpoints each error with a clear explanation so you can fix it in a few seconds and stay in control of the result.

Does it support JSON with comments (JSONC or JSON5)?

No. The validator follows the strict JSON standard (RFC 8259), so comments, trailing commas and single quotes are reported as errors. That is deliberate: it tells you whether a standard parser will accept your file.

How large a file can I format?

Files of several megabytes format in well under a second on a typical laptop. The tree view displays the first 5,000 values to keep the page responsive, while the formatted text always contains the entire document.

Why did a long number change after formatting?

JavaScript represents numbers as 64-bit floating point values, which are exact only up to 9,007,199,254,740,991. Larger integers lose precision when parsed. If exact values matter, store such IDs as strings.

What does “Sort keys A–Z” do?

It reorders the keys of every object alphabetically, at all nesting levels, without changing any values or array order. This makes two versions of the same data easy to compare in a diff tool.

Does the formatter work offline?

Yes. Once the page has loaded, everything runs locally, so you can keep using it without an internet connection.