Dev

How to Format JSON — Beginner's Guide

JSON is everywhere in modern development. Learn what JSON is, why formatting matters, and the fastest way to pretty-print or validate any JSON blob.

4 min read

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
Developer looking at code on a monitor
Formatting JSON makes complex data structures immediately recognizable.

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 // comments or /* 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

Always format JSON before committing to version control — it makes code reviews significantly easier and diff outputs much cleaner.

How to Format JSON in VS Code

VS Code has excellent built-in JSON formatting. Follow these steps:

1

Open your JSON file in VS Code

Make sure the file has a .json extension so VS Code recognizes it as JSON automatically.
2

Trigger the formatter

Press Shift + Alt + F on Windows/Linux or Shift + Option + F on Mac. VS Code will auto-indent and format the entire file.
3

Alternative: right-click menu

Right-click anywhere in the file and select Format Document, or use the command palette (Ctrl+Shift+P) and search for "Format Document".

Note

If VS Code is not formatting correctly, ensure the language mode in the bottom status bar says JSON, not Plain Text.

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?

When using our tool, your data is processed entirely in your browser. No JSON is ever sent to our servers, keeping your API keys and configuration values private.

Can I format JSON with comments?

Standard JSON does not support comments. However, many formatters (including ours) can optionally strip comments or alert you if they are present.

What is the difference between JSON and JSON5?

JSON5 is a proposed extension to JSON that allows trailing commas, single quotes, and comments. Standard JSON is much more strict.

OneClickTool Team

We build fast, free, privacy-focused tools for everyone. No signup, no data collection — ever.

→ Browse all 172+ free tools
📬

Get notified when we launch new tools

New free tools every week — no spam, one-click unsubscribe.

You might also like