JSON Formatter & Validator
Pretty-print, minify and validate JSON with exact error positions.
What "valid JSON" actually means
JSON has a famously small grammar — it fits on a single index card — which is exactly why the errors are so annoying: there are only a handful of things that can go wrong, and they all look identical in a minified five-megabyte file. A JSON document is one value, which must be one of:
- an object — unordered key/value pairs, keys must be double-quoted strings
- an array — an ordered list of values
- a string — double quotes only; single quotes are invalid
- a number — no leading zeros, no
NaN, noInfinity true,false, ornull— lowercase and unquoted
Notice what is not on that list: comments, trailing commas, unquoted keys,
and undefined. If you pasted a config file that "looks like JSON" and it
failed validation, it is almost certainly one of those four.
The five errors that cause almost every JSON bug
1. Trailing commas
JavaScript object literals tolerate them; JSON does not. This is the single most common failure when people hand-edit a config file:
{
"host": "localhost", // valid
"port": 8080, // <-- trailing comma makes the whole document invalid
}
2. Single-quoted strings
{ 'name': 'devforge' } // invalid — JSON requires double quotes
{ "name": "devforge" } // valid
3. Smart quotes from a word processor
If your JSON passed through Word, Google Docs, or a chat app, curly quotes
(“ ”) may have replaced straight ones (" "). They are
different Unicode code points and JSON rejects them. They are also nearly invisible
in most editors — this is the one that wastes the most time.
4. Comments
JSON has no comment syntax. If you need comments, use JSONC (and a JSONC parser),
YAML, or put documentation in a sibling README. The formatter will
reject anything with // or /* */ in it.
5. Numbers that aren't numbers
Leading zeros (007), a bare .5, NaN,
Infinity, and hex literals are all invalid. Valid numbers look like
0, -12, 3.14, or 1.0e10.
Pretty-print vs. minify
They are the same operation with different arguments, and the choice is about transport, not correctness. Whitespace between structural tokens is not significant: these two documents parse to the identical value.
// Minified — smallest payload over the wire
{"name":"devforge","tags":["json","tools"],"stars":1280}
// Pretty-printed — readable in a diff, a review, or a config file
{
"name": "devforge",
"tags": ["json", "tools"],
"stars": 1280
}
A useful rule: minify on the wire, pretty-print in the repository. Minified JSON is smaller and therefore faster to transfer; pretty-printed JSON produces clean, reviewable diffs because a one-line change touches one line. Storing minified JSON in git makes every change a one-line diff that rewrites the whole file.
Why pretty-printed JSON matters in code review
Version control diffs are line-based. In a minified file, adding one key rewrites
the entire line, so git diff shows the whole document as changed and
reviewers cannot see what you actually did. In a pretty-printed file, adding a key
adds a line. This is why nearly every package manager — npm, Cargo, Poetry — writes
lockfiles with two-space indentation even though nobody reads them by hand.
Sorting keys: when it helps and when it hurts
Alphabetically sorting keys produces stable, deterministic output, which is valuable for snapshot tests and for diffing two responses that should be identical. It is harmful for config files where key order carries meaning, and for documents where a human curated the order for readability. Enable it when you are producing machine-comparable output; leave it off when a person will read the result.
Handling very large documents
Browsers can parse multi-megabyte JSON comfortably, but the bottleneck is usually display, not parsing. If you are working with a file in the tens of megabytes, validate it from the command line instead — it is faster and will not lock up your tab:
# Validate and pretty-print without leaving the shell
python3 -m json.tool input.json > output.json
# Or check validity only (exit code 0 = valid)
python3 -c "import json,sys; json.load(open(sys.argv[1]))" input.json
Frequently asked questions
No. Parsing happens with the browser's built-in JSON engine inside your own tab. There is no network request containing your data, and nothing is stored after you close the page.
In order of likelihood: a trailing comma, a single-quoted string, a smart quote copied from a document or chat app, a comment, or a number with a leading zero. The validator reports the line and column of the first character it could not parse.
There is no hard limit imposed by this tool — the practical ceiling is your browser's memory and your patience with rendering a very long output. Documents up to a few megabytes are comfortable; beyond roughly 50 MB, use a command-line tool instead.
No. Formatting only changes insignificant whitespace. Ordering of object keys is preserved unless you explicitly enable sorting — and even then, key order is not semantically meaningful in JSON.
Not directly. JSON5 and JSONC allow comments, trailing commas and unquoted keys, all of which are invalid in strict JSON. Strip those features first, or use a parser that targets the dialect you are working in.