JSON Formatter & Validator

Beautify, minify, sort keys alphabetically, and validate JSON — plus a collapsible tree view for exploring the structure, with clear error messages when something's wrong.

How to Format and Validate JSON

  1. Paste your JSON into the input box.
  2. Choose an indent size — 2 spaces, 4 spaces, or a tab — and optionally check "Sort keys alphabetically".
  3. Click "Format / Beautify" to pretty-print it, or "Minify" to collapse it onto a single line.
  4. Switch the Result panel to "Tree View" to explore valid JSON as a collapsible, expandable outline instead of raw text.
  5. Copy the result with "Copy Result", or click "Clear" to start over with new input.

Frequently Asked Questions

How does the formatter find the exact error location?

It runs your text through the browser's native JSON.parse; when parsing fails, the tool extracts the character position from the resulting error message and counts newlines up to that point to report the specific line and column, instead of leaving you to decode a raw "unexpected token" message.

What's the difference between Format and Minify?

Format/Beautify re-serializes your JSON with the indentation you chose — 2 spaces, 4 spaces, or a tab. Minify re-serializes it with no whitespace at all, which is useful for shrinking a payload before sending it over a network.

Does it validate JSON strictly?

Yes — it uses the browser's built-in JSON.parse, the same strict parser your own JavaScript code would use, so anything that fails here (trailing commas, unquoted keys, single-quoted strings, comments) would also fail if you tried to parse it in real code.

Can it automatically fix invalid JSON?

No — it only reports where the syntax breaks. You still need to edit the reported line and column yourself before Format or Minify will succeed.

Is my JSON uploaded anywhere?

No — parsing, formatting, and minifying all happen locally using your browser's own JSON engine, so nothing you paste ever leaves your device.

What does "Sort keys alphabetically" actually change?

When checked, the tool recursively rewrites every object in your JSON so its keys appear in A-to-Z order before formatting, minifying, or building the tree view. Array order is never touched — only the key order inside objects changes — and the underlying data and values are otherwise identical, so this is purely a readability aid.

What is the Tree View mode?

Tree View is an alternative way to browse valid JSON as a collapsible, indented outline instead of raw text — click any object or array's toggle to expand or collapse its children, which makes it easier to explore deeply nested structures than scrolling through a flat text block. It reflects the same Sort Keys setting as the text output.