HTML Formatterhtmlformatteronline.com

JSON formatter and validator

Format, check and minify JSON in one place. When it will not parse, the error names the line and tells you what is actually wrong — not just where the parser gave up.

Your JSON 0 lines
Format
Formatted 0 lines
Paste JSON on the left, then press the button.

What this does

It parses your JSON, then writes it back out with one key per line and a fresh indent at every level of nesting. Because it parses rather than pattern-matches, anything it returns is guaranteed to be valid JSON — and anything it cannot return tells you exactly where the problem is.

One line, unreadable
{"sku":"A-100","title":"Linen shirt","price":58,"stock":{"s":4,"m":0,"l":12}}
Formatted
{
  "sku": "A-100",
  "title": "Linen shirt",
  "price": 58,
  "stock": {
    "s": 4,
    "m": 0,
    "l": 12
  }
}

The errors it catches before the parser does

A browser's own JSON error messages are famously unhelpful. "Unexpected token } in JSON at position 247" tells you where the parser gave up, which is rarely where you made the mistake. This tool scans for the specific things people actually get wrong and names them:

'

Single-quoted strings

Legal in JavaScript, illegal in JSON. Every string and every key must use double quotes.

,

Trailing commas

[1, 2, 3,] is fine in modern JavaScript and rejected by every JSON parser.

//

Comments

JSON has none. If you need them, you want JSON5 or YAML, or a key called _comment.

key:

Unquoted keys

{ name: "x" } is a JavaScript object literal, not JSON.

None

Python values

None, True and False mean you printed a Python dict instead of serialising it. The tool says so.

NaN

NaN and Infinity

Valid JavaScript numbers, but not valid JSON. They usually arrive from a maths error upstream.

Six mistakes in six lines — paste this and press Check
{
  'name': 'Acme Supply',
  open: true,
  // opening hours
  "hours": [9, 17,],
  "rating": NaN,
  "owner": None
}

Sort keys

Ticking Sort keys A–Z reorders every object alphabetically, all the way down. Two uses for it:

Comparing two files. JSON objects have no defined key order, so two API responses with identical content can produce a completely unreadable diff. Sort both and the diff shows only what actually changed.

Finding a key in a large document. In a config file with ninety keys, alphabetical order means you can scan to roughly the right place instead of reading all of it.

Sorting changes key order, which is not meaningful in JSON — no parser cares. It is safe on config and API data. The one exception is a file a human maintains where the grouping is deliberate; sorting that destroys the grouping, and you cannot get it back.

Where JSON usually comes from broken

Copied out of a browser console. Chrome's console prints objects with unquoted keys and single quotes. That display format is not JSON. Right-click the network response and use Copy response instead.

Printed by a program rather than serialised. Python's print(my_dict) gives you {'a': None}. Use json.dumps(). PHP's print_r has the same problem; use json_encode.

Hand-edited config. Trailing commas and comments, almost always, because the person editing it writes JavaScript all day.

Truncated in transit. A log line cut at a fixed width, or a response that hit a size limit. The tool will tell you which bracket never closed.

Questions about this tool

Is my JSON sent anywhere?

No. It is parsed by JSON.parse in your own browser. There is no server call — open the Network tab and press Format to confirm. That matters for JSON, which so often contains API keys, customer records or internal configuration.

Why does it say my JSON is invalid when my app reads it fine?

Your app is probably not using a strict JSON parser. JavaScript's eval, Python's ast.literal_eval and several YAML parsers will all happily read things that are not JSON. Strict parsers — which is what the receiving end usually is — will not.

Can it handle very large files?

Up to a few megabytes comfortably. Everything runs on your device, so the limit is memory rather than a server quota. Past roughly 10 MB a browser textarea becomes sluggish regardless of what the parser is doing — at that size a command-line tool like jq is the better instrument.

Does formatting change my data?

Only the whitespace, with one thing worth knowing: numbers are re-serialised, so 1.50 comes back as 1.5 and 1e3 as 1000. Those are the same JSON number. If you are storing money or precise identifiers as numbers, that is a reason to store them as strings instead — not a reason to avoid formatting.

What about JSON Lines or NDJSON?

Those are files with one JSON document per line, so paste a single line at a time. Formatting the whole file at once would fail, because the file as a whole is not one JSON document.

Related tools

Learn the why, not just the how

Longer reading on formatting, indentation and minification.