Dev tools2 min read

How to Format, Validate and Minify JSON (and Find the Error)

Paste messy or minified JSON and make it readable, minify it for config, or find exactly which line and column breaks it. Runs privately in your browser.

By the ZapMorph team

JSON Formatter
On this page
  1. How to format JSON with ZapMorph
  2. The usual suspects
  3. More errors and their fixes
  4. Formatted vs minified
  5. JSON-like formats that aren't JSON
  6. Related
  7. Summary
  8. FAQs

Just want it done?

Open the JSON Formatter & Validator — it runs in your browser and nothing is uploaded.

Open the tool

Minified JSON from an API, a log line, or a config file someone edited by hand: unreadable at best, broken at worst. The JSON formatter makes it readable, tells you exactly where it's broken, and can squash it back down when you're done.

How to format JSON with ZapMorph

1. Open the JSON formatter

Go to the JSON formatter & validator.

JSON formatter page
The JSON formatter

2. Paste your JSON

Paste it in, or open a .json file. Choose your indentation, or minify. If it's invalid, you'll see the line and column of the problem.

Formatted, valid JSON in the formatter
Formatted and validated

The usual suspects

{
  "name": "Ana",
  "tags": ["a", "b",],     <- trailing comma: not allowed
  'city': "Lisbon",        <- single quotes: not allowed
  age: 34                  <- unquoted key: not allowed
}

Fix those three and most "invalid JSON" errors disappear.

More errors and their fixes

ErrorCauseFix
Unexpected token /A // commentRemove comments (JSON has none)
Unexpected end of inputMissing } or ]Check brackets are balanced
Bad control characterA real line break inside a stringUse \n instead
Unexpected token NNaN or NoneUse null
Unexpected token TTrue from PythonUse lowercase true
Invalid escapeSingle backslash in a Windows pathDouble it: C:\\Users

Formatted vs minified

{"user":{"id":42,"roles":["admin","editor"]}}
{
  "user": {
    "id": 42,
    "roles": ["admin", "editor"]
  }
}

Same data. The first is smaller, the second is readable.

JSON-like formats that aren't JSON

  • JSON5 and JSONC (VS Code settings, tsconfig.json) allow comments and trailing commas. Strict JSON parsers reject them.
  • JavaScript objects allow unquoted keys and single quotes.
  • Python dicts printed with print() use single quotes and True/None. Use json.dumps() instead.

Summary

The JSON formatter makes JSON readable, finds errors precisely and never sends your data anywhere.

FAQs

How do I find where my JSON is broken?

Paste it in. Invalid JSON is flagged with the line and column of the problem.

What are the most common JSON errors?

Trailing commas, single quotes instead of double quotes, unquoted keys, and comments. JSON allows none of them.

Is it safe to paste API responses with tokens?

Yes. Nothing you paste leaves your browser.

Should I use 2 or 4 spaces?

Either is fine. 2 spaces is the most common in JavaScript projects and APIs; follow whatever your project already uses.

Why minify JSON?

Minified JSON removes whitespace, making files and API payloads smaller. It's harder for people to read, so keep a formatted copy for editing.

What's the difference between the formatter and the JSON viewer?

The formatter works on the text: indenting, minifying and validating. The viewer turns valid JSON into a collapsible tree for exploring large files.

Try the JSON Formatter & Validator

Free to start, no install, and your files never leave your device.

Open the tool

Related guides

All guides