JSON Formatter & Validator
Format, minify, validate and sort JSON entirely in your browser. Precise error messages with line and column, and nothing is ever uploaded.
How to use this calculator
- 1Paste your JSON into the box.
- 2Choose formatted, minified, or formatted with keys sorted.
- 3If it is invalid, the error tells you the line, column and surrounding text.
How the calculation works
JSON.parse(input) → transform → JSON.stringify(value, null, indent)- parse
- Validates the syntax and builds an in-memory value
- stringify
- Serialises it back out with the chosen indentation
Round-tripping through the parser is what makes this a validator as well as a formatter: invalid JSON cannot be parsed, so it cannot be formatted.
Sorting keys makes two JSON documents comparable with a plain text diff, since JSON object key order is not semantically meaningful.
Worked example
Formatting a compact object
- 1.The input parses cleanly as an object with four top-level keys.
- 2.Re-serialising with two-space indentation produces readable, nested output.
- 3.The structure is 6 keys across 2 objects and 1 array, nested 3 levels deep.
Result: Valid JSON, formatted with 2-space indentation
What JSON actually is
JSON — JavaScript Object Notation — is a lightweight, text-based format for representing structured data: objects, arrays, strings, numbers, booleans and null, nested as deeply as needed. Despite the name, it is not tied to JavaScript; the syntax was extracted from a subset of JavaScript object-literal notation because it was already familiar and easy to read, but every mainstream programming language now has a JSON parser, which is what turned it into a genuinely language-independent format.
The appeal is that a JSON document is both machine-parseable and human-readable at the same time. A developer can open a JSON file, glance at it, and understand the shape of the data — something that is much harder with binary formats — while a parser can turn the same text into native objects in a few lines of code.
Why it replaced XML for most web APIs
Before JSON became the default, XML was the standard way to exchange structured data between a server and a browser, including in the AJAX techniques that made modern interactive web pages possible. XML is powerful — it supports namespaces, schemas and mixed content — but that power comes with verbosity: every value needs an opening and closing tag, attributes add another layer of syntax, and there is no native representation for something as simple as an array.
JSON, popularized in the early 2000s by Douglas Crockford, mapped directly onto data structures JavaScript already had — objects and arrays — so a browser could turn a JSON response into usable data with a single parse call, no separate library required. Combined with a much smaller footprint on the wire, that made it the practical choice for web APIs, and by the 2010s it had displaced XML as the default format for nearly every new API, though XML remains common in older enterprise systems, document formats and configurations that predate the shift.
The syntax rules, precisely
JSON’s syntax is deliberately small, and every rule in it is strict — there is no lenient mode in the specification, which is why a single stray comma can invalidate an entire document.
- Keys must be double-quoted strings — unlike JavaScript object literals, single quotes and unquoted keys are not valid JSON, even though they are valid JavaScript.
- No trailing commas — a comma after the last item in an object or array is a syntax error, even though many languages tolerate it.
- No comments — JSON has no comment syntax at all. This is a deliberate design choice, not an oversight — Crockford has said comments were removed to keep parsers simple and interoperable.
- Only six data types — string, number, object, array, boolean and null. There is no date type, no undefined, and no way to represent a function — dates are conventionally passed as ISO 8601 strings instead.
- Numbers have no special integer type — JSON numbers are just numbers; how a parser stores them (as a 64-bit float, a bignum, or something else) is left to the implementation, which is why very large integers can lose precision in JavaScript.
Where JSON shows up today
What began as a way to move data between a browser and a server has spread to nearly every corner of software development.
- Web APIs — the near-universal format for REST and GraphQL request and response bodies.
- Configuration files — package.json, tsconfig.json and countless other tool configs use it, valued for being both human-editable and trivially parseable.
- NoSQL databases — document stores like MongoDB store records as JSON-like documents natively, rather than in fixed relational tables.
- Logging — structured logging tools emit one JSON object per line, so logs can be filtered, searched and aggregated by machine rather than read as loose text.
What this assumes, and where it stops
Assumptions
- Input is standard JSON as defined by RFC 8259.
Limitations
- JSON5, JSONC and other relaxed dialects — trailing commas, comments, unquoted keys, single quotes — are not accepted, because the standard parser rejects them.
- Numbers are parsed as IEEE-754 doubles, so integers beyond 2⁵³ lose precision. This is a property of JSON in JavaScript, not of this tool.
- Duplicate keys are silently resolved to the last occurrence, as the specification permits.
Common questions
Is my data sent to a server?
No. The parsing, formatting and validation all run in your browser using the built-in JSON parser. Nothing leaves your device. You can verify this by opening the network tab and formatting something — there is no request.
Why does my JSON with comments fail?
Standard JSON does not permit comments — the specification deliberately excludes them. Formats like JSONC and JSON5 add them back, but they are separate dialects. Strip comments and trailing commas to make the document valid JSON.
Why do my large numbers change?
JavaScript parses JSON numbers as 64-bit floats, which represent integers exactly only up to 9,007,199,254,740,991. Larger identifiers lose precision. The usual fix is to transmit them as strings.
Sources
Formula and content last reviewed on .
Results are estimates for information only, not professional advice.
Related calculators
Tools people commonly use alongside the json formatter & validator.