What is JSON Formatter?

JSON Formatter takes raw or minified JSON and indents it so you can read it, or compacts it into a single line to save space. It also validates JSON syntax and shows errors with line numbers, which helps when debugging APIs or inspecting data.

The formatter parses with the built-in JSON.parse and re-serialises with the indent you choose: 2 spaces, 4 spaces, or tabs. The tree view renders nested objects and arrays as collapsible nodes so you can drill into a deeply nested API response without scrolling. Errors point to the exact line and a short message so syntax bugs are quick to fix.

How to use

  1. Step 1 — Paste your JSON string into the input area. Syntax errors show up highlighted as you type.
  2. Step 2 — Choose your indent size (2 or 4 spaces, or tabs) and click Format to pretty-print, or Minify to compress to a single line.
  3. Step 3 — Copy the formatted output or download it as a .json file. Toggle tree view to browse nested keys, then type in the search box to jump straight to any field.

When to use

  • Reading a minified API response from a curl or fetch debug log without paging through one giant line.
  • Spotting a stray comma or unquoted key in a config file before the deploy step rejects it.
  • Minifying a large fixtures file before checking it into the repo to keep diffs and bundle size down.

Result

An API returns a minified 500-line JSON response. Paste it in, select 2-space indent, and you'll see the nested structure with collapsible sections. Find the 'user.preferences.notifications' path in seconds.

FAQ

Why does the formatter say my JSON is invalid when it looks fine?
JSON is strict about quotes and commas. Keys must use double quotes ("name", not 'name'), trailing commas after the last item are not allowed, and comments are not part of the spec. The error message gives the line number for the first parse failure.
What is the difference between formatting and minifying JSON?
Formatting adds indentation and line breaks so the structure is easy to read by eye. Minifying strips all whitespace into a single line, which is faster to transfer over the network and uses less disk. Both produce identical data when parsed.
Can the tool handle very large JSON files?
Yes. Files up to several megabytes parse in well under a second on modern devices because everything runs locally. The tree view does add memory overhead for objects with tens of thousands of leaves; switching back to plain text view keeps it light.
Should I use 2 spaces, 4 spaces, or tabs for indentation?
Most JavaScript and config repos default to 2 spaces, which matches Prettier and the Node ecosystem. 4 spaces is common in Java and Python communities. Tabs are useful when contributors want to choose their own visual width.
Can I sort the keys alphabetically?
Yes. Tick the Sort keys checkbox before clicking Format or Minify and every object will be re-emitted with its keys in alphabetical order. Arrays keep their original order. This is handy for stable diffs and for normalising config files written by hand.

Related Tools