Skip to content
TechSolveTools

How to Format JSON (Beautify, Validate & Fix Errors)

4 min readUpdated 5 October 2026

To format JSON, paste it into JSON Formatter: it is pretty-printed as you type, with 2-space indentation and colour highlighting. Switch to 4 spaces or tabs, Sort keys or Minify if you need to, then Copy the result or Download .json. If the JSON is invalid, you get the error with its line and column, and Go to error jumps straight to it.

It is free, needs no sign-up and works on any device. Everything runs in your browser and your JSON is never sent to a server, which matters when you're pasting API responses that contain tokens, emails or customer data.

Step by step

  1. 1Paste your JSONPaste JSON into the Input pane, drop a .json file onto it, or use the open-file button (files up to 20 MB). Press Sample to try it with example data.
  2. 2Check the status barValid JSON shows a green Valid JSON with the number of keys, the nesting depth and the size. Invalid JSON shows the error message, its line and column, and the surrounding text with the problem character highlighted.
  3. 3Fix any errorsPress Go to error to select the problem character in the input. Correct it and the output updates immediately — repeat until the status turns green.
  4. 4Choose the layoutKeep Format and pick 2 spaces, 4 spaces or Tabs. Switch on Sort keys to order keys A–Z at every level, or choose Minify to strip all whitespace.
  5. 5Explore, copy or downloadSwitch the output between Code and Tree. In the tree, tap a key to copy its path, such as $.author.name. Then press Copy, or Download .json to save a file.

How to fix invalid JSON: the usual suspects

JSON Formatter doesn't guess and rewrite your data — it shows you exactly where the parser stopped, so you stay in control of what changes. Nearly every error is one of these:

  • A trailing comma — a comma right before } or ], as in [1, 2, 3,]. Delete it.
  • Single quotes — JSON needs double quotes around both strings and keys: {'a': 'b'} becomes {"a": "b"}.
  • Unquoted keys — {name: "Ann"} is valid JavaScript but not JSON; write {"name": "Ann"}.
  • Comments — // and /* */ aren't allowed in JSON. Remove them.
  • A missing comma or bracket — between two items, or at the very end. The error is often reported on the next line.
  • Non-JSON values — True, False and None from Python, or undefined and NaN from JavaScript. Use true, false and null.
  • Curly quotes — “smart” quotes copied from Word, a chat or a document look right but aren't valid. Retype them as straight quotes.

Tip: The reported position is where the parser gave up, which is often just after the real mistake. If the highlighted spot looks fine, check the end of the previous line.

Format or minify?

Formatted (“beautified” or pretty-printed) JSON puts each key on its own line with indentation, so you can read nested data, spot missing fields and review changes. Use it while debugging and in files people edit by hand.

Minified JSON removes every unnecessary space and line break. The data is identical, just smaller — useful for pasting into a single-line config value, a URL parameter or a request body.

Reading large JSON with the tree view

API responses can run to thousands of lines. Tree view shows the structure instead: objects and arrays fold open and closed, each shows how many keys or items it holds, and very long arrays show the first 200 items with a button to show more.

Tap any key to copy its path — for example $.tools[1].slug — ready to use in code or a query. Very large outputs are shown without colour highlighting so the page stays fast.

Related tools for working with JSON

Once your JSON is valid, these tools help with the next step:

  • CSV ↔ JSON — turn a spreadsheet export into JSON, or JSON back into a table.
  • YAML ↔ JSON ↔ XML — convert config files between formats.
  • Diff Checker — format two JSON files with Sort keys on, then compare them line by line.
  • JWT Decoder — read the JSON inside a login token without sending it anywhere.

Questions people ask

Can the tool fix my JSON automatically?
No. It shows the exact line, column and character where the JSON breaks and takes you there with Go to error, so you decide the fix and nothing in your data changes silently.
Why is JSON with comments marked invalid?
Standard JSON doesn't allow comments. Some config files use relaxed variants such as JSONC or JSON5 that do, but a strict parser — like the one in most programming languages — rejects them. Remove the comments to get valid JSON.
Is it safe to paste API responses or tokens?
Yes. The formatting happens in your browser and nothing you paste is sent to a server.
What does Sort keys do?
It orders the keys of every object alphabetically, including nested objects. Arrays keep their original order, because order matters in a list.
How large a JSON file can I format?
You can open files up to 20 MB. Big documents depend on your device's memory, but typical API responses and config files format instantly.

More guides