JSON shows up everywhere: in API responses, configuration files, and data passed between web apps. Yet many beginners meet it for the first time as an intimidating wall of brackets and quotes, usually at the exact moment something is broken. This guide walks through what JSON actually is, how to read it, how to format it so humans can understand it, and how to fix the errors that trip up almost everyone at first.
What JSON is (and what it isn't)
JSON stands for JavaScript Object Notation. Despite the name, it's a language-independent data format — a standardised way of writing structured information as plain text so that different programs can exchange it. A weather app, a payment service, and your browser can all read the same JSON even though they're written in different programming languages.
Here's a small, complete example:
{ "name": "Ayesha", "age": 29, "isStudent": false, "courses": ["Maths", "Physics"] }
Even if you've never seen JSON before, you can probably guess what this describes: a person named Ayesha, aged 29, who is not a student and takes two courses. That readability is JSON's whole point — it's structured enough for machines and plain enough for humans.
How to read JSON: the building blocks
Everything in JSON is built from a handful of pieces:
- Objects — wrapped in curly braces
{ }. An object holds named values:{ "city": "Lahore" }. - Key-value pairs — each piece of data has a name (the "key", always in double quotes) and a value:
"city": "Lahore". - Arrays — wrapped in square brackets
[ ]. An array is an ordered list:["red", "green", "blue"]. - Values — can be text (in double quotes), numbers (no quotes),
true/false,null(meaning "no value"), or nested objects and arrays.
Objects and arrays nest inside each other freely. An object can contain an array, which contains objects, and so on. When JSON gets hard to read, it's almost always because of deep nesting — which is exactly what formatting fixes.
Minified vs. formatted JSON
JSON you'll encounter "in the wild" often looks like this — everything on one line with no spaces:
{"users":[{"id":1,"name":"Ayesha","roles":["admin","editor"]},{"id":2,"name":"Bilal","roles":["viewer"]}],"total":2}
This is called minified JSON. Machines love it because it's compact and fast to transfer. Humans hate it because a single misplaced character is nearly impossible to spot in a 5,000-character line.
Formatted (or "pretty-printed") JSON is the same data with indentation and line breaks:
Each object opens on its own line, nested items are indented, and the structure becomes visible at a glance. Formatting doesn't change the data at all — it's purely for human eyes. The standard convention is 2 or 4 spaces of indentation per level.
As a rule of thumb: transfer minified, read formatted. APIs send minified JSON to save bandwidth; you format a copy when you need to inspect or debug it.
How to validate JSON
Validation means checking that your JSON follows the rules exactly. JSON is strict — far stricter than most beginners expect. A single misplaced comma makes the entire document invalid, and the program reading it will refuse it outright rather than guess what you meant.
The practical workflow is:
- Paste your JSON into a validator/formatter. A free JSON formatter will both check the syntax and pretty-print the result in one step.
- Read the error message. Validators tell you the line and position of the first problem, e.g. "Unexpected token } at line 12". Fix that one error first — later errors are often knock-on effects.
- Fix, re-validate, repeat. Keep going until the validator reports the JSON as valid.
The mistakes almost every beginner makes
These five errors account for the vast majority of invalid JSON:
- Trailing commas.
{"a": 1, "b": 2,}— that comma after the last item is illegal in JSON (even though JavaScript allows it). Remove it. - Single quotes.
{'name': 'Ayesha'}is invalid. JSON requires double quotes around all keys and text values. - Unquoted keys.
{name: "Ayesha"}is invalid. Every key must be quoted:{"name": "Ayesha"}. - Comments. JSON has no comments —
// noteor/* note */will break validation. (Some "JSON-like" config formats allow them; strict JSON does not.) - Mismatched brackets. Every
{needs a}and every[needs a], properly nested. Formatting the JSON makes these dramatically easier to spot.
There's also a subtler one: numbers with leading zeros (007) and special values like NaN or Infinity are not valid JSON, even though some programming languages produce them.
Formatting JSON by hand: a practical approach
When you need to understand a blob of minified JSON, don't try to read it raw. Instead:
- Paste it into a JSON formatter to get the indented version.
- Collapse the sections you don't care about (most formatters and code editors let you fold nested blocks).
- Read from the outside in: identify the top-level keys first, then drill into the one relevant section.
- For very large responses, search within the formatted output (Ctrl/Cmd+F) for the key name you're interested in rather than scrolling.
If you're writing JSON by hand — say, a config file — write it formatted from the start with consistent indentation, and validate it before saving. Catching a missing comma takes ten seconds with a validator and can take an hour of debugging without one.
Frequently asked questions
Is JSON the same as a JavaScript object?
They look similar but aren't identical. JSON is a text format with stricter rules: keys must be double-quoted, no trailing commas, no comments, no functions. A JavaScript object literal is actual code and is more permissive. You can convert between them, but you can't paste arbitrary JavaScript into a JSON validator and expect it to pass.
What's the difference between JSON and XML?
Both are data formats, but JSON is more compact and maps directly onto the data structures (objects, arrays, strings, numbers) that most programming languages use natively. XML is more verbose but supports features like attributes and mixed content. For new APIs, JSON is the near-universal default today.
Can JSON contain dates?
JSON has no dedicated date type. Dates are conventionally written as text in ISO format, e.g. "2026-10-15" or "2026-10-15T14:30:00Z", and the receiving program interprets them. Just make sure both sides agree on the format and timezone.
How large can a JSON file be?
There's no formal limit, but practical ones apply: browsers and editors slow down noticeably past a few megabytes, and many APIs cap request bodies (commonly 1–10 MB). For genuinely large datasets, formats designed for streaming or databases are a better fit than one giant JSON document.