Format
JSON Formatter, Validator and Repair
Beautify, minify, validate and repair broken JSON entirely in your browser.
Runs entirely in your browser — nothing you paste is uploaded or stored.
What is json formatter?
A JSON formatter takes JSON that is hard to read — a minified API response, a config file with inconsistent indentation, a log line containing an embedded payload — and re-prints it with consistent indentation so the structure is obvious at a glance. This tool also validates as it goes: if the JSON is malformed, it tells you what is wrong and where, rather than silently producing nothing — and where the problem is one of the familiar ones, it offers to repair the document for you. It can minify in the other direction, and sort object keys alphabetically so two documents can be compared meaningfully.
When to use it
- Reading a minified API response that arrived as one enormous single line, where finding a particular field by eye is otherwise impossible.
- Checking whether a config file is valid JSON before deploying it, so a missing comma fails on your machine rather than in production.
- Minifying a JSON payload before embedding it somewhere size-sensitive, such as a data attribute or an environment variable.
- Sorting keys on two versions of the same document so that a diff shows real changes instead of key-order noise.
- Rescuing a hand-edited config file or a JavaScript object literal that is almost JSON but has trailing commas, comments or single quotes.
How to use this tool
- Paste your JSON into the input pane on the left. Formatting happens as you type — there is no button to press.
- Choose Beautify, Minify or Sort keys, and pick the indentation you prefer (2 spaces, 4 spaces, or tabs).
- If the JSON is invalid, an error appears explaining the problem and the character position where the parser gave up.
- If the document can be salvaged, a panel lists exactly what would change and offers a "Fix it" button. Nothing is altered until you press it.
- Use the Copy button to put the result on your clipboard.
Example
A minified API response, beautified with 2-space indentation.
Input
{"id":42,"name":"Ada","roles":["admin","dev"],"active":true}Output
{
"id": 42,
"name": "Ada",
"roles": [
"admin",
"dev"
],
"active": true
}The tool also reports structural statistics — key count, nesting depth and total nodes — which is often the fastest way to sanity-check an unfamiliar payload.
The most common ways JSON breaks
“Valid JSON” is a narrower category than most people expect. In rough order of how often they turn up:
- Trailing commas —
[1, 2, 3,]. Legal in JavaScript, never in JSON. - Single-quoted strings —
{'a': 1}. JSON strings must use double quotes. - Unquoted keys —
{a: 1}. Object keys are strings and need quoting. - Comments —
//and/* */are not part of the format, however useful they are. - Smart quotes —
{"a": "b"}with curly quotes, usually from pasting through a word processor, chat client or ticket description. - Python literals —
True,FalseandNoneinstead oftrue,falseandnull. NaN,Infinityandundefined— JSON has no representation for any of them, so a serialiser that emits them has produced something no parser will read back.- Truncation — a log line or clipboard copy that cut off mid-document.
- Unescaped newlines inside a string value.
- Duplicate keys — technically parseable, but the earlier value is silently lost.
The repair feature handles all of these. The first four are worth learning to spot by eye, because they account for the large majority of “why won’t this parse” moments.
Frequently asked questions
Is my JSON sent to a server?
No. The formatting, validation and sorting all happen in JavaScript inside your own browser tab. No network request is made with your data, which means it is safe to paste API responses containing tokens or personal information. You can confirm this yourself by opening your browser's Network tab while using the tool — you will see no outbound requests.
Why does sorting keys leave my arrays in the original order?
Because array order is data, not formatting. Reordering the elements of an array changes what the document means, so this tool deliberately never touches it. Only the keys within objects are sorted, since JSON object key order carries no semantic meaning per the specification.
What does the error message mean when it mentions a position?
The position is the character offset in your input where the JSON parser encountered something it could not handle. It is usually a few characters after the actual mistake — a missing comma or an unclosed bracket earlier in the document often only becomes unparseable later on. Look slightly before the reported position.
Can it handle very large JSON files?
It handles files of a few megabytes comfortably. Because everything runs in your browser tab, extremely large documents (tens of megabytes) may make the page feel sluggish while parsing, since the work competes with rendering on the same thread. For files that size, a command-line tool such as jq is a better fit.
Does it support JSON5, comments, or trailing commas?
Validation is against the strict JSON specification, which permits neither — so if a document passes here, it will parse in any standards-compliant parser. But the repair feature accepts all of these as input and converts them to strict JSON, which is usually what you want when a file was hand-written or copied out of JavaScript source.
What can the repair feature actually fix?
The common causes of invalid JSON — trailing commas, single-quoted strings, unquoted object keys, // and /* */ comments, curly "smart" quotes pasted from a word processor, Python's True/False/None, NaN and Infinity, missing commas or colons, unclosed brackets, and surrounding text such as a log-line prefix. It also finds JSON embedded in a longer line and wraps newline-delimited documents into an array.
Is it safe to trust the repaired output?
Treat it as a well-informed guess, not a certainty. The repair is done by a real parser rather than find-and-replace, so it will not corrupt braces, commas or comment-like text that appear inside string values, and the result is always verified to be valid JSON before it is offered. But recovering a truncated or badly mangled document involves inferring intent, so check the result before relying on it. Nothing is changed until you press "Fix it", and every change is listed first.
Why does the repair remove one of my duplicate keys?
Because every JSON parser already does. When an object contains the same key twice, the specification leaves the behaviour undefined and in practice parsers keep the last occurrence — meaning the earlier value was already being silently discarded. The repair makes that explicit rather than leaving a document whose meaning depends on which parser reads it.