JSON for Beginners: Format, Validate & Fix Errors
JSON is the language the modern web speaks: APIs return it, apps store it, and config files are written in it. Yet its strict little rules trip up beginners and veterans alike. This guide teaches you to read JSON fluently, format it beautifully, validate it confidently, and fix the errors you will inevitably meet.
On this page
- What JSON is (and isn’t)
- Syntax: the six building blocks
- Formatting vs. minifying
- The 5 errors everyone makes
- Debugging workflow
- FAQ
What JSON is (and isn’t)
JSON — JavaScript Object Notation — is a text format for structured data. It was derived from JavaScript but is language-independent: Python, PHP, Java, Go, and virtually every modern language can read and write it. What it is not: a programming language (no logic, no comments, no functions), and not the same as a JavaScript object — JSON is stricter, as you are about to see.
Syntax: the six building blocks
Everything in JSON is one of six things:
| Type | Example | Rules |
|---|---|---|
| Object | {“a”: 1} | Curly braces, key–value pairs |
| Array | [1, 2, 3] | Square brackets, ordered list |
| String | “hello” | Double quotes only |
| Number | 42, 3.14, -7 | No quotes, no NaN/Infinity |
| Boolean | true / false | Lowercase, no quotes |
| Null | null | Lowercase, means “no value” |
A realistic example:
{
"name": "Ada Lovelace",
"born": 1815,
"mathematician": true,
"languages": ["English", "French"],
"mentor": null
}
Read it inside-out: an object with five keys, whose values are a string, a number, a boolean, an array of strings, and null.
Formatting vs. minifying
Formatting (beautifying) expands compact JSON into indented, readable form — what you want when debugging. Minifying strips every unnecessary space to shrink the payload — what you want when sending data over the network. Validating checks correctness without changing anything. Our free JSON formatter does all three, with error messages that point at the exact problem.
The 5 errors everyone makes
- Trailing commas. {“a”: 1,} — that last comma is illegal. Valid in JavaScript, invalid in JSON. Remove it.
- Single quotes. {‘a’: 1} — JSON demands double quotes for all strings and keys, no exceptions.
- Unquoted keys. {a: 1} — keys must be quoted strings: {“a”: 1}.
- Comments. JSON has no // or /* */. Config files using “JSON with comments” (JSONC) must be stripped before parsing.
- Unescaped inner quotes. “say “hi”” breaks parsing — escape them: “say \”hi\””. Same for backslashes (\) and newlines (\n).
A debugging workflow that works
When an API response or config file fails: 1) paste it into the formatter and hit Validate; 2) read the error message — it names the position; 3) look at the highlighted surrounding text for one of the five errors above; 4) fix and re-validate; 5) format to confirm the structure is what you expect. Ninety percent of JSON bugs die at step 3.
For large files, bisect: validate the first half. If it passes, the error is in the second half. Repeat — you will find any error in logarithmic time.
Frequently asked questions
What is the difference between JSON and a JavaScript object?
JSON is a text format with strict rules (double quotes, no comments, no functions). A JavaScript object is a live data structure with looser syntax. JSON.parse() converts the text into the object.
Can JSON contain comments?
Strictly, no. Some tools accept “JSONC” (JSON with comments), but standard parsers reject it — strip comments before validating.
Why does my valid-looking JSON fail?
Usual suspects: a trailing comma, single quotes, an invisible character (like a smart quote pasted from Word), or a BOM at the file start. The validator’s position hint finds it.
Is there a size limit for JSON?
The format itself has none; limits come from parsers and memory. Our formatter comfortably handles multi-megabyte documents.
FH
The SomethingWebTools Team
We build free, private, browser-based tools — and write guides so you can use them like a pro.
Try it now: Free JSON Formatter →
One Comment