How to use this JSON formatter
Paste your JSON into the input box on the left, or click Open file… to load a .json file from your computer. Then pick an action:
- Format / Beautify re-indents the document so each key sits on its own line and nesting is easy to follow. Choose two spaces, four spaces or tabs from the Indent menu. The shortcut is Ctrl + Enter (⌘ + Enter on a Mac).
- Minify removes every unnecessary space and line break, producing the smallest valid representation. This is what you want for embedding JSON in a URL parameter, an environment variable or a request body where size matters.
- Validate checks the syntax without changing the output box. If the JSON is valid you get a summary of its size, number of values and nesting depth; if not, you get the exact line and column of the problem.
Switch to Tree view to browse the parsed data as collapsible branches. Each object shows how many keys it has and each array how many items, so you can find the part you care about without scrolling through thousands of lines. Hover over any node to see its path, such as $.address.city or $.roles[1], which you can reuse in JSONPath queries or in code.
The Sort keys A–Z option reorders object keys alphabetically at every level. It is useful when you want to compare two API responses or config files in a diff tool, because the same data will then always produce the same text.
What makes JSON invalid?
JSON looks like JavaScript, but its grammar (defined in RFC 8259) is much stricter. Almost every error people hit falls into a handful of categories, and the validator names them in plain English:
- Trailing commas.
[1, 2, 3,]and{"a": 1,}are accepted by JavaScript and many config parsers but are not valid JSON. - Single quotes. Strings and keys must use double quotes.
{'name': 'Ada'}fails;{"name": "Ada"}works. - Unquoted keys.
{name: "Ada"}is a JavaScript object literal, not JSON. - Missing commas between two values or two key–value pairs, often after you paste lines together.
- Comments. Neither
//nor/* */comments are allowed. Formats such as JSONC and JSON5 permit them, but a standard JSON parser will reject them. - Special values.
undefined,NaNandInfinitydo not exist in JSON. Python’sTrue,FalseandNoneare also invalid; the JSON spellings aretrue,falseandnull. - Raw line breaks inside strings. A newline inside a string must be written as
\n. - Leading zeros and bare decimals.
007and.5are invalid numbers; write7and0.5.
Click Try a broken sample to see how errors are reported. The status bar names the problem, the line number in the gutter turns red, and a context panel shows the surrounding lines with a caret under the exact character. Go to error moves your cursor there so you can fix it immediately.
Reading an error message correctly
A parser reports the place where it noticed the problem, which is not always where the mistake was made. If you forget a comma at the end of line 3, the error is usually reported at the start of line 4, because that is where the parser finds a second value it did not expect. When the message says “Expected “,” or “}” after object value”, look at the end of the previous line first. Similarly, an unterminated string is reported where the string started, since the parser cannot know where you meant it to end.
Formatting versus minifying: when to use which
Formatted JSON is for humans. Use it when reading API responses, reviewing configuration in pull requests, or writing documentation. Two-space indentation is the most common convention in JavaScript projects, while four spaces is typical in Python’s json.dumps(indent=4) output. Tabs keep files slightly smaller and let each reader choose their own visual width.
Minified JSON is for machines. Whitespace is meaningless to a parser, so stripping it reduces payload size, often by 10–30% for heavily nested data. If your server already uses gzip or Brotli compression, the saving on the wire is much smaller because whitespace compresses extremely well, so minification matters most where compression is not applied: local storage, query strings, message queues and logs.
Practical tips
- Large numbers. JavaScript stores numbers as 64-bit floating point, so integers above 9,007,199,254,740,991 (253 − 1) lose precision when parsed. If your API returns 64-bit IDs, the formatted output may show a slightly different number. This is a property of JavaScript, not of the data; many APIs send such IDs as strings for this reason.
- Duplicate keys. JSON technically allows an object to repeat a key, but parsers disagree about which value wins. This tool, like browsers, keeps the last one. If formatting makes a key “disappear”, check for duplicates.
- Byte order marks. Files saved by some Windows editors start with an invisible BOM character. The validator tolerates it, but some strict parsers do not.
- Logs with one object per line. Newline-delimited JSON (NDJSON) is not a single JSON document. Validate one line at a time, or wrap the lines in
[ ]and add commas. - Diffing configs. Format both versions with the same indentation and sorted keys, then compare them. Differences in whitespace and key order disappear, leaving only real changes.
A quick example
This minified response from an API is hard to read:
{"user":{"id":42,"tags":["beta","pro"],"plan":null}}
After formatting with two-space indentation it becomes:
{
"user": {
"id": 42,
"tags": [
"beta",
"pro"
],
"plan": null
}
}
In the tree view the same document collapses to a single user branch with three keys, and hovering over "pro" shows its path, $.user.tags[1].
Your data stays on your device
API payloads often include access tokens, email addresses or internal hostnames, so pasting them into a website that uploads them is a real risk. JSON Lens parses and formats everything with JavaScript running in your browser tab. There is no server-side processing and nothing is saved, which also means the tool keeps working if you lose your connection after the page has loaded.
Frequently asked questions
Is my JSON uploaded to a server?
No. Formatting, validation, minification and the tree view all run in JavaScript inside your browser. The JSON you paste is never sent anywhere and is discarded when you close the tab.
Why does the error point to the line after my mistake?
A parser reports where it noticed the problem. A missing comma at the end of one line is detected when the next value starts, so check the end of the previous line as well as the reported position.
Can this tool fix invalid JSON automatically?
It does not silently rewrite your data, because guessing the intended structure can introduce subtle bugs. Instead it pinpoints each error with a clear explanation so you can fix it in a few seconds and stay in control of the result.
Does it support JSON with comments (JSONC or JSON5)?
No. The validator follows the strict JSON standard (RFC 8259), so comments, trailing commas and single quotes are reported as errors. That is deliberate: it tells you whether a standard parser will accept your file.
How large a file can I format?
Files of several megabytes format in well under a second on a typical laptop. The tree view displays the first 5,000 values to keep the page responsive, while the formatted text always contains the entire document.
Why did a long number change after formatting?
JavaScript represents numbers as 64-bit floating point values, which are exact only up to 9,007,199,254,740,991. Larger integers lose precision when parsed. If exact values matter, store such IDs as strings.
What does “Sort keys A–Z” do?
It reorders the keys of every object alphabetically, at all nesting levels, without changing any values or array order. This makes two versions of the same data easy to compare in a diff tool.
Does the formatter work offline?
Yes. Once the page has loaded, everything runs locally, so you can keep using it without an internet connection.