If you've ever received a wall of compressed JSON like {"name":"Alice","age":30,"active":true} and had to stare at it to figure out the structure, you'll understand why formatting matters.
What Is JSON?
JSON stands for JavaScript Object Notation. It's a lightweight, text-based format for storing and exchanging data. Almost every web API returns data in JSON format, and most programming languages can read it natively.
A formatted JSON object looks like this:
{
"name": "Alice",
"age": 30,
"active": true,
"tags": ["developer", "designer"],
"address": {
"city": "Toronto",
"country": "Canada"
}
}json
The Rules of Valid JSON
JSON has strict formatting rules. These are the most common mistakes that cause JSON to break:
- Trailing commas:
{"name": "Alice",}— the comma after the last item is invalid. - Single quotes: All strings must use double quotes, not single quotes.
- Unquoted keys:
{name: "Alice"}is JavaScript, not valid JSON — keys must be quoted. - Comments: JSON does not support
// commentsor/* block comments */. - Undefined / functions: Only strings, numbers, booleans, null, objects, and arrays are valid JSON values.
Formatting vs. Minifying
There are two common operations you'll perform on JSON:
- Pretty-print / Format: Adds indentation and line breaks to make JSON human-readable. Use this for debugging and reviewing data.
- Minify: Strips all whitespace and line breaks to reduce file size. Use this in production APIs and bundled config files to save bandwidth.
Use formatted JSON for debugging and code review. Use minified JSON in production for faster transfers.
Pro Tip
Free tools mentioned in this article
→ Browse all free toolsHow to Format JSON in VS Code
VS Code has excellent built-in JSON formatting. Follow these steps:
Open your JSON file in VS Code
.json extension so VS Code recognizes it as JSON automatically.Trigger the formatter
Shift + Alt + F on Windows/Linux or Shift + Option + F on Mac. VS Code will auto-indent and format the entire file.Alternative: right-click menu
Ctrl+Shift+P) and search for "Format Document".Note
How to Validate JSON
Validation checks that your JSON is syntactically correct. A good formatter will report errors with line numbers. Common error messages and what they mean:
Unexpected token— usually a missing quote, comma, or brace.Expected , or }— you're missing a comma between key-value pairs.Unexpected end of input— the JSON is incomplete; you're missing a closing bracket or brace.Duplicate key— the same key appears twice in one object (technically allowed but not recommended).
Fastest Option: Free Online JSON Formatter
For quick formatting without opening VS Code, use our free JSON Formatter. Paste your JSON, click Format, and it's instantly pretty-printed and validated — all in your browser, nothing sent to a server.
- Formats and validates JSON with one click
- Shows clear error messages with line numbers
- Minify option for production-ready output
- Copy to clipboard button for fast workflow
Common Questions
Is my data safe when using an online JSON formatter?
Can I format JSON with comments?
What is the difference between JSON and JSON5?


