~/TechPurAILearn · Build · Grow
Start Learning
~/tools/json-formatter
Testing & Validation

JSON Formatter & Validator

Indent
Input
1
2
3
4
5
6
7
8
9
10
11
Output
{ 6 keys
name:"TechPurAI"
tagline:"learn to build, skip the fluff"
tools:23
free:true
categories: [ 3 items
0:"generators"
1:"seo-essentials"
2:"testing-validation"
]
founder: { 2 keys
name:"Vijay Kumar"
role:"Founder"
}
}
244 characters · 244 B · 11 lines

JSON looks simple enough to write by hand until a single trailing comma or an unquoted key quietly breaks it — and because JSON has no comments and no forgiving parser built into most tools, the resulting error is often a flat "Unexpected token" with no indication of what's actually wrong. This tool formats, minifies, and validates JSON entirely in your browser, and when something doesn't parse, it points at the exact line and column instead of leaving you to scan the whole file by eye.

Format, minify, or browse as a tree

Three output modes cover the three reasons people actually reach for a JSON tool. Format adds readable indentation (2 spaces, 4 spaces, or a tab, your choice) for writing, debugging, or reviewing a config file or API response. Minify strips that back down to the shortest valid representation — the version that actually belongs in a production response, where every byte of whitespace is pure overhead. Tree renders the parsed structure as a collapsible, color-coded outline instead of flat text, which is often the faster way to find one specific field buried in a large, deeply nested payload than reading indented text top to bottom.

An optional "sort keys alphabetically" toggle reorders every object's keys recursively before formatting or minifying — useful specifically for diffing two versions of the same JSON, since a tool that diffs text literally will show every line as changed if the key order differs, even when nothing of substance did.

Reading a validation error

When the input doesn't parse, the error box shows the line and column where the parser gave up, plus the underlying message. It's worth knowing that this location is where parsing stopped, not necessarily where the mistake was made — a missing comma between two object properties, for instance, isn't detected until the parser reaches the next line and finds something it didn't expect there, so the reported line is often one past the actual problem. If the flagged line looks fine on its own, the line directly above it is the next place to check.

Fixing the two mistakes that cause most "broken" JSON

An enormous share of JSON that fails to validate isn't actually broken data — it's a JavaScript object literal that got copied and pasted as if it were JSON, and the two formats are similar enough that the difference is easy to miss. JavaScript object literals tolerate a trailing comma before a closing } or ]; JSON does not. JavaScript tolerates an unquoted key like {name: "value"}; JSON requires {"name": "value"}. The Try to fix button repairs both automatically, which resolves the large majority of real-world "why won't this validate" cases in one click. It deliberately doesn't attempt to fix single-quoted strings, since converting those safely requires understanding exactly where a string starts and ends — something a quick text replacement can get wrong in a way that silently corrupts otherwise-valid data, which defeats the point of a "fix."

Syntax valid isn't the same as data correct

A JSON document can be perfectly well-formed and still be missing a field your code expects, have a string where a number belongs, or use the wrong key name entirely — none of which a syntax validator like this one is designed to catch. That's the job of JSON Schema validation, a separate and more specialized check against a shape you define, not something this tool does.

Frequently asked questions

Why does my JSON fail to validate when it looks correct?

The two most common causes by far are a trailing comma before a closing bracket (valid in a JavaScript object literal, invalid in JSON) and an object key that isn't wrapped in double quotes — both are things JavaScript itself tolerates, which is exactly why copying an object straight out of JS source code so often produces JSON that won't parse. This tool's Try to fix button repairs both automatically; anything else gets flagged with the exact line and column where parsing actually stopped.

Why does the error message give a line number that doesn't look like where the problem actually is?

A JSON parser reports where it stopped being able to continue, not necessarily where the mistake was introduced — a missing comma after one value, for instance, is only detected when the parser reaches the start of the next one, which can be a line or more later. If the reported line looks correct syntactically, check the line immediately before it first; that's where a missing comma, bracket, or quote usually actually lives.

Does this tool validate JSON against a schema, or only check that it's syntactically valid?

Only syntax — that any text you provide is well-formed JSON per the JSON specification (RFC 8259). It doesn't check whether the data matches a particular shape, required fields, or value types, which is what JSON Schema validation does. For most everyday uses — checking a config file, an API response, or a paste that silently broke — syntax validity is the actual question being asked; schema validation is a separate, more specialized need.

What's the difference between the Format and Minify output?

Format adds indentation and line breaks so the structure is readable by a person — useful while writing, debugging, or reviewing JSON. Minify strips every unnecessary space and line break down to the shortest valid representation of the same data, which is what you actually want in a production API response or a file being transferred, since every extra byte of whitespace is wasted bandwidth with zero effect on what the data means.

Is it safe to paste JSON that contains real data, like an API key or customer record, into this tool?

Nothing you paste, upload, or generate here is sent anywhere — formatting, validating, and the tree view all run entirely in your browser using JSON.parse() and JSON.stringify(), the same built-in functions any JavaScript environment uses, not a server-side service. That said, as a general habit, avoid pasting production secrets into any web tool you don't control the source of; this one simply doesn't have a server component to leak them to in the first place.

Why does the tree view collapse some sections by default?

Arrays and objects with more than 20 items start collapsed so a large JSON payload doesn't render as an overwhelming wall of expanded nodes the moment it's pasted — everything smaller than that opens expanded automatically. Click any collapsed section's triangle to open it; the state isn't saved between edits, so re-pasting resets it.