What Is JSON and How to Use It: A Plain-English Guide
By Deepak·
JSON (JavaScript Object Notation) is a lightweight text format for storing and sharing data. It is the most common way web apps, APIs, and config files send structured data between a server and a browser — and learning to read and write it takes about ten minutes.
What Does JSON Actually Look Like?
JSON stores data as key-value pairs inside curly braces {}. Think of it like a labelled box: each label (key) points to a value.
Here is a real example — a simple user profile in JSON (language: JSON):
{
"name": "Maria Lopez",
"age": 28,
"isPremium": true,
"skills": ["Python", "SQL", "JavaScript"],
"address": {
"city": "Barcelona",
"country": "Spain"
}
}
Every piece of data has a clear label. Arrays (lists) use square brackets []. Nested objects sit inside their own curly braces. That is the whole structure — there is nothing hidden.
The Six Value Types You Need to Know
JSON supports exactly six data types. Knowing them prevents most beginner mistakes:
- String — text in double quotes:
"hello" - Number — integer or decimal, no quotes:
42,3.14 - Boolean — true or false (lowercase, no quotes):
true,false - Array — an ordered list:
["a", "b", "c"] - Object — nested key-value pairs:
{"key": "value"} - Null — an empty / missing value:
null
One rule that trips people up early: all keys must be strings in double quotes. Single quotes are not valid JSON, even though they work fine in JavaScript itself.
How to Use JSON in Practice
The two most common tasks are parsing (turning a JSON string into data your code can use) and stringifying (turning your data back into a JSON string to send somewhere).
Here is how both work in JavaScript (language: JavaScript):
// Parse a JSON string into a JavaScript object
const jsonString = '{"name": "Maria", "age": 28}';
const user = JSON.parse(jsonString);
console.log(user.name); // Maria
// Turn a JavaScript object into a JSON string
const newUser = { name: "Carlos", age: 34 };
const output = JSON.stringify(newUser);
console.log(output); // {"name":"Carlos","age":34}
JSON.parse() and JSON.stringify() are built into every modern browser and Node.js — no library needed. Python uses json.loads() and json.dumps(); the pattern is identical.
What Is JSON Used For? Real-World Examples
Once you spot JSON, you see it everywhere:
- REST APIs — when your weather app fetches a forecast, the server replies with JSON data.
- Config files —
package.jsonin Node.js,tsconfig.jsonfor TypeScript, VS Code settings. - Databases — MongoDB stores documents as BSON (a binary form of JSON). PostgreSQL has a native
jsonbcolumn type. - Logging — structured logs in JSON format are easy to search and filter in tools like Datadog or CloudWatch.
How JSON Compares to XML and YAML
Before JSON became dominant, XML was the standard. Here is a quick comparison:
| Format | Human-readable | Supports comments | Verbosity | Best for |
|---|---|---|---|---|
| JSON | Yes | No | Low | APIs, data exchange |
| XML | Moderate | Yes | High | Documents, SOAP services |
| YAML | Very high | Yes | Very low | Config files, DevOps |
JSON wins on simplicity and universal language support. Nearly every programming language has a built-in JSON parser — it is defined in RFC 8259, the official internet standard.
Common JSON Mistakes (and How to Fix Them Fast)
These are the errors you will hit sooner or later:
- Trailing comma — a comma after the last item in an object or array. Valid in JavaScript, invalid in JSON. Example:
[1, 2, 3,]will throw a parse error. - Single quotes instead of double quotes —
{'name': 'Maria'}is not valid JSON. - Comments — JSON has no comment syntax.
// this will breakinside a JSON file causes a parse error. - Unescaped special characters — a literal newline or tab inside a string value must be written as
\nor\t. - Wrong number format — leading zeros like
007are not valid JSON numbers.
If you are staring at a parse error and cannot spot the issue, paste your JSON into a free JSON validator — it highlights the exact line and character where the problem is.
Tools That Make Working with JSON Easier
Raw JSON can be hard to read when it arrives as a single compressed line. A few tools fix that instantly:
- JSON Formatter — formats and validates in one step, great for checking API responses.
- JSON Beautifier — adds indentation and colour so nested objects are easy to follow.
- JSON Pretty Print — the same idea optimised for quick copy-paste readability.
- JSON Minifier — strips whitespace before you send data over a network to save bandwidth.
- JSON Viewer — lets you explore a deeply nested structure in a collapsible tree view.
All of these run in your browser — nothing to install, nothing to sign up for.
FAQ: What People Ask About JSON
Is JSON only for JavaScript?
No. Despite the name, JSON works with virtually every programming language. Python, Java, PHP, Go, Ruby, C#, and Rust all have native or standard-library JSON support. The format is language-agnostic — that is exactly why it became the default for APIs that connect systems written in different languages.
What is the difference between JSON and a JavaScript object?
A JavaScript object is live data in memory — it can have functions, undefined values, and keys without quotes. JSON is a text format — a plain string that follows strict rules. You convert between the two with JSON.parse() and JSON.stringify(). They look similar but are not the same thing.
Can JSON store images or binary files?
Not directly. JSON handles text only. To include binary data — like an image — you first encode it as a Base64 string (a text representation of binary data), then store that string as a JSON value. This works but adds about 33% to the file size, so most APIs send a URL pointing to the file instead.
How do I validate JSON to check if it is correct?
Paste it into a free online JSON validator for instant feedback — it shows the exact line with the error. In code, wrap JSON.parse() in a try/catch block: if parsing throws a SyntaxError, the JSON is invalid. The error message usually names the position of the problem.