What Is JSON and How to Format It Correctly

JSON is a lightweight, text-based format for structuring data, built from a small set of simple rules — but even a single misplaced comma or quote can make it invalid.

Key Points

  • JSON is built from objects {}, arrays [], and a small set of value types (strings, numbers, booleans, null).
  • JSON syntax is strict: double-quoted keys only, no trailing commas, correctly matched braces/brackets.
  • JSON is language-independent, despite the name referencing JavaScript.
  • Formatting/indentation isn't required for validity, but makes JSON much easier for humans to read and debug.

What JSON Is

JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data, widely used for exchanging data between a server and a web application, storing configuration, and many other purposes. Despite its name referencing JavaScript, JSON is language-independent and used across virtually every modern programming language.

The Basic Building Blocks

JSON is built from just a few structures: objects (key-value pairs wrapped in curly braces {}), arrays (ordered lists of values wrapped in square brackets []), and a small set of value types — strings (in double quotes), numbers, booleans (true/false), null, and nested objects or arrays. Every piece of JSON data is some combination of these building blocks.

Strict Syntax Rules

Unlike more forgiving formats, JSON has strict rules: property names must be in double quotes (not single quotes), there must be no trailing comma after the last item in an object or array, and every opening brace/bracket must have a matching closing one in the correct place. A single missing comma, an extra comma, or using single quotes instead of double quotes is enough to make an entire JSON document invalid — most parsers won’t try to guess what you meant.

A Simple Example

A basic JSON object might look like:

{
  "name": "Example",
  "active": true,
  "tags": ["one", "two"],
  "details": { "count": 5 }
}

Notice the double-quoted keys, no trailing commas, and properly nested braces/brackets.

Why Formatting (Not Just Validity) Matters

Technically, JSON doesn’t require any specific whitespace or indentation to be valid — a whole document can be on one line. But for a human reading or editing JSON, consistent indentation and line breaks (called ‘pretty-printing’) make the structure vastly easier to follow, especially in deeply nested data. A JSON formatter takes valid (or sometimes invalid) JSON and reformats it consistently, while also flagging syntax errors that would otherwise be hard to spot by eye — particularly useful when working with minified JSON from an API response or debugging a hand-written config file.

Frequently Asked Questions

Why does my JSON show an error even though it looks fine?

A very common cause is a trailing comma after the last item in an object or array, or using single quotes instead of double quotes around keys/strings — both make JSON invalid even though they're easy to miss visually.

Can JSON have comments?

No — standard JSON does not support comments. Some tools accept a relaxed variant (like JSON5) that does, but strict JSON parsers will reject a document containing them.

Explore More

Browse every free calculator and tool, or find more practical guides.