What Is a JSON Formatter — and How to Fix Invalid JSON
A JSON formatter is a tool that re-indents JSON so it's easy to read (beautify), collapses it to the smallest valid form (minify), and checks whether it's valid (validate). It only ever changes whitespace — never your actual data. If your JSON won't parse, a formatter's validator pinpoints the error, which is usually a trailing comma, a single quote, an unquoted key, or a missing bracket.
Key takeaways
- Beautify adds indentation and line breaks; minify strips them; validate confirms it parses.
- Formatting changes whitespace only — the data is identical before and after.
- Most "invalid JSON" errors are trailing commas, single quotes, unquoted keys, or unbalanced brackets.
- A browser-based JSON formatter keeps your payloads private — nothing is uploaded.
What a JSON formatter actually does
JSON (JavaScript Object Notation) is the standard format for exchanging data between apps, APIs and config files. It's just text — but text that has to follow strict rules. A JSON formatter helps you work with it in three ways:
- Beautify (pretty-print): takes a dense, single-line blob and re-indents it with consistent spacing and line breaks, so you can actually see the nested structure. This is the most common use — turning an unreadable API response into something you can scan.
- Minify: the reverse — it removes every optional space and line break to produce the smallest valid JSON. Useful when you're embedding JSON in a URL, a config value, or anywhere size matters.
- Validate: checks whether the text is valid JSON at all, and if not, tells you where it breaks.
Crucially, none of these change your data. Beautifying and minifying only add or remove whitespace; the keys, values, and structure stay exactly the same.
Why is my JSON invalid? The five most common causes
JSON has a strict, unforgiving grammar. Almost every "invalid JSON" error comes down to one of these:
- 1. Trailing comma. A comma after the last item in an object or array —
{"a": 1,}— is valid in JavaScript but not in JSON. Remove it. - 2. Single quotes. JSON requires double quotes around both keys and string values.
{'a': 'b'}is invalid;{"a": "b"}is correct. - 3. Unquoted keys. Keys must be quoted strings.
{a: 1}is invalid;{"a": 1}is correct. - 4. Missing or mismatched brackets. Every
{needs a}and every[needs a]. A single missing brace breaks the whole document. - 5. Comments. Standard JSON does not allow
//or/* */comments. Strip them out.
A validator reads the JSON with a strict parser and reports the first error it hits, often with a position, so you can jump straight to the offending character instead of hunting by eye.
Beautify vs. minify: when to use each
Reach for beautify whenever you need to read JSON: debugging an API response, reviewing a config file, or understanding someone else's data structure. Indented JSON with each key on its own line is far easier to scan and diff.
Reach for minify whenever size or transport matters: embedding JSON in a query string, storing it in an environment variable, or shaving bytes off a payload. Minified JSON is functionally identical — just smaller.
A note on privacy
Many online JSON tools send whatever you paste to a remote server to format it. That's a genuine risk when your JSON contains access tokens, personal data, or an internal API response. A formatter that runs in your browser does all the parsing locally with the same engine your browser already uses, so nothing is transmitted. If you regularly paste sensitive payloads, prefer a client-side tool.
Frequently asked questions
What does a JSON formatter do?
A JSON formatter re-indents JSON with consistent spacing and line breaks so nested structure is easy to read (beautify), collapses it to the smallest valid form (minify), and checks whether it parses at all (validate). It changes only whitespace, never the data.
Why is my JSON invalid?
The most common causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, or a missing bracket or brace. A validator points to the error so you can fix the exact character.
Is it safe to paste JSON into an online formatter?
It depends on the tool. Many formatters send your data to a server. A browser-based formatter does the work entirely on your device, so even sensitive payloads and tokens never leave your computer.
Related: JSON Formatter · Base64 Encode / Decode · all Developer Tools