How to use the JSON Formatter
- 1
Paste your JSON into the left box, or click Load sample to try it with example data.
- 2
Choose an indent of 2 spaces, 4 spaces or a tab.
- 3
Press Format to beautify, Minify to strip whitespace, Validate to only check syntax, or Sort keys to order every object alphabetically.
- 4
If there is a mistake, read the red message: it gives the line, the column and a caret under the problem character.
- 5
Copy the result, download it as a .json file, or switch to Tree view to fold and unfold nested objects.
Why API responses arrive as one long line
Servers almost always send JSON minified. Spaces and line breaks mean nothing to a parser, so dropping them saves bandwidth on every request. That is great for the network and terrible for you when you are trying to find one field inside a 40 KB response from a payment gateway or a GST e-invoice API.
Formatting puts each key on its own line and indents nested objects so the structure becomes visible. You can see at a glance that items is an array of three objects, that address sits inside customer, and that a value you expected to be a number is actually a string in quotes.
The tool never changes your data while formatting. It parses the text with the browser's own JSON.parse and writes it back with JSON.stringify, so what you get is the same document with different whitespace.
Common JSON errors and how to fix them
JSON looks like a JavaScript object, but the rules are much stricter. Nearly every error people hit comes from writing JavaScript habits into a JSON file. These are the ones this validator catches most often, with the exact fix.
| Mistake | Invalid example | Valid version |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'city': 'Pune'} | {"city": "Pune"} |
| Unquoted key | {name: "Asha"} | {"name": "Asha"} |
| Comment | {"debug": true // remove later} | {"debug": true} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Leading zero | {"pin": 0411} | {"pin": "0411"} |
| JavaScript-only values | {"x": undefined, "y": NaN} | {"x": null, "y": null} |
| Line break typed inside a string | "line one (Enter) line two" | "line one\nline two" |
When the parser stops, the error box shows the line and column and draws a caret under the character where things went wrong. Remember that the real mistake is sometimes just before that spot. A missing comma, for example, is reported at the start of the next key, because that is where the parser realised something was off.
Different browsers word their JSON errors differently, and Safari does not give a position at all. This page runs its own small scanner to find the position and describe the problem in plain words, then also shows the browser's original message underneath for reference.
Format, minify, validate or sort: which button to use
Format is what you want most of the time. Two spaces is the common style in JavaScript projects, four spaces is typical in Python and Java codebases, and a tab lets each person's editor decide the width.
Minify does the opposite and removes every space that is not inside a string. Use it before pasting JSON into an environment variable, a single-line config field or a request body where size matters. The success message tells you how many bytes you saved.
Validate only checks syntax and confirms the document is valid.
Sort keys reorders the keys of every object, at every level, alphabetically. Arrays keep their original order because order in an array carries meaning. Sorting is the trick for comparing two API responses: sort both, then run them through a diff tool and only the real differences show up.
Reading the stats and the tree view
After a successful run you see the output size in bytes, the total number of keys across all levels, the nesting depth and the type of the top-level value. Depth is a quick sanity check. If a simple settings file reports a depth of 12, something is probably wrapped inside itself by mistake.
The tree view is useful for large documents. Nodes open two levels deep by default, and each collapsed node shows how many keys or items it holds, so you can jump straight to the part you care about without scrolling through thousands of lines. Very large arrays show the first 500 entries in the tree; the text output always has everything.
Things a JSON formatter will quietly change
Because the tool parses and re-serialises your data, a few edge cases are worth knowing about before you trust the output for production.
- Duplicate keys: JSON.parse keeps only the last value for a repeated key, so {"a": 1, "a": 2} becomes {"a": 2}. If your output has fewer keys than you expected, look for duplicates.
- Big integers: JavaScript numbers are exact only up to 9007199254740991. A 19-digit order ID or a Twitter-style snowflake ID written as a number will be rounded. Ask the API to send such IDs as strings.
- Number formatting: 1.0 becomes 1 and 1e3 becomes 1000. The value is the same, the text is not.
- Escapes: \u20B9 is written back as the actual ₹ character. It is identical JSON, just more readable.
Files like tsconfig.json or VS Code's settings.json allow comments and trailing commas because they use a relaxed format often called JSONC. Strict JSON parsers reject those, so this validator will flag them. That is correct behaviour, not a bug.
Is it safe to paste production data here?
The formatting, validation and tree view all run in JavaScript inside your browser tab. The JSON you paste is not uploaded, logged or stored, and it is gone when you close or refresh the page. That matters when the payload contains customer phone numbers, PAN details or access tokens.
Frequently asked questions
How do I find the error in invalid JSON?
Paste it and press Validate or Format. The red box shows the line and column number, a short explanation such as trailing comma or single quotes, and the offending line with a caret under the exact character. Fix that spot and run it again, since one file can contain several mistakes.
Why does my JSON have a trailing comma error when JavaScript accepts it?
JavaScript object literals allow a comma after the last item, but the JSON standard does not. Remove the comma before the closing } or ] and the error goes away.
Can JSON contain comments?
No. Standard JSON has no comment syntax, so // and /* */ cause a parse error. Some tools accept a relaxed variant with comments, but anything that calls JSON.parse will reject them. Move notes into a separate field like "_note" if you really need them.
Is there a size limit for this JSON formatter?
There is no fixed limit because everything runs on your device. Files of a few megabytes format in well under a second on a normal laptop. Formatting happens only when you press a button, so typing in a big document does not slow the page down.
What is the difference between JSON beautify and JSON minify?
Beautify, or format, adds line breaks and indentation so people can read it. Minify removes all of that so the file is as small as possible for machines. The data inside is identical either way.
Does sorting keys change my data?
Only the order of keys inside objects changes. Values, array order and nesting stay exactly the same, and any program reading the JSON will treat it as the same data.
Last updated on November 9, 2026