This JSON formatter and validator turns messy or minified JSON into clean, indented text, or squeezes it back into one line. If the JSON is invalid, it shows the parser’s error message so you can find the problem fast. Your data is parsed on your own device and never sent to a server, which matters when it contains API keys or customer records.
How to use the JSON formatter
- Paste your JSON into the input box.
- Choose an indent: 2 spaces, 4 spaces or tabs.
- Click Format to pretty-print, or Minify to remove all whitespace.
- Turn on Sort keys if you want object keys in alphabetical order, which makes two files easier to compare.
- If you see an error message, fix the line it points to and try again. Then copy the result.
How it works
The tool uses the browser’s built-in JSON parser, the same one JavaScript applications use. Formatting is a two-step process: first the text is parsed into data, then it is written back out with your chosen indentation. If parsing fails, nothing is changed and the error is shown instead. Because the data is rebuilt from scratch, the output is always valid JSON when no error appears.
Sorting keys reorders the properties inside every object, at every level, alphabetically. Arrays are never reordered, because in JSON the order of array items is meaningful.
Example
Here is minified JSON from an API response:
{"user":{"name":"Ana","id":42,"active":true},"tags":["finance","tech"]}
Formatted with 2 spaces and sorted keys, it becomes:
{
"tags": [
"finance",
"tech"
],
"user": {
"active": true,
"id": 42,
"name": "Ana"
}
}
Note that “tags” moved above “user” and the keys inside “user” are now in alphabetical order, while the order of the two tags did not change.
Common JSON errors and fixes
JSON is stricter than JavaScript. Most errors come from a short list of mistakes:
| Problem | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1,} |
{"a": 1} |
| Single quotes | {'a': 'x'} |
{"a": "x"} |
| Unquoted keys | {a: 1} |
{"a": 1} |
| Comments | {"a": 1 // note} |
Remove the comment |
| Special values | {"a": undefined} |
{"a": null} |
| Missing comma between items | [1 2] |
[1, 2] |
Other things to check: every opening brace or bracket needs a matching closing one, strings cannot contain raw line breaks (use n), and numbers cannot have leading zeros such as 007. The error message usually gives a position or line number; the real mistake is often just before that point.
When to format and when to minify
- Format when you are reading, debugging or reviewing JSON, writing config files, or committing data to version control, where line-by-line changes are easier to review.
- Minify when you send JSON over a network or store it, since whitespace adds bytes but no meaning.
- Sort keys before comparing two JSON files, so differences in key order do not hide the real changes.
Two spaces is the most common indent in web projects; four spaces is common in Python projects. Tabs let each reader set their own width. Pick one style per project and keep it.
If your JSON holds credentials, rotate any secret you may have pasted into an online tool that does upload data, and use our password generator to create a strong replacement.
Frequently asked questions
Is it safe to paste API responses or config files here?
Yes. The JSON is parsed in your browser and is not uploaded or logged. You can even disconnect from the internet after the page loads and it will still work.
Why does it say my JSON is invalid when it works in JavaScript?
JavaScript object syntax allows single quotes, unquoted keys, trailing commas and comments. Strict JSON allows none of these, so convert them as shown in the table above.
Does sorting keys change my data?
No. JSON objects are unordered, so sorting keys does not change their meaning. Arrays keep their original order.
Can very large numbers lose precision?
Yes. Integers larger than 9,007,199,254,740,991 cannot be stored exactly in JavaScript and may be rounded when formatted. Store such IDs as strings.
Should I use 2 spaces, 4 spaces or tabs?
Any of them is valid JSON. Use whatever your project or team already uses so files stay consistent.
