What is JSON? Everything You Need to Know
General • Concepts Explained • 6 min read
JSON is everywhere — APIs, config files, data storage. Learn what JSON is, how to use it, and common mistakes to avoid.
What is JSON? Everything You Need to Know
JSON is everywhere. APIs send data in JSON. Configuration files use JSON. If you're a developer, you'll work with JSON daily. Let's understand it completely.
What is JSON?
JSON stands for JavaScript Object Notation. It's a lightweight format for storing and exchanging data. It's easy for humans to read and easy for machines to parse.
{
"name": "John",
"age": 25,
"isActive": true,
"hobbies": ["reading", "gaming", "coding"]
}
JSON Data Types
- String — Text in double quotes:
"hello" - Number — Integers or decimals:
42,3.14 - Boolean — True or false:
true,false - Array — Ordered list:
[1, 2, 3] - Object — Key-value pairs:
{"key": "value"} - Null — Empty value:
null
JSON vs JavaScript Objects
JSON looks like JavaScript objects, but there are differences:
// JavaScript object (no quotes on keys)
const user = { name: "John", age: 25 };
// JSON (quotes required on keys)
const jsonString = '{"name": "John", "age": 25}';
JSON is a text format. JavaScript objects are in-memory structures. You convert between them using JSON.parse() and JSON.stringify().
Working with JSON in JavaScript
// Parse JSON string to object
const data = JSON.parse('{"name": "John", "age": 25}');
// Convert object to JSON string
const json = JSON.stringify({ name: "John", age: 25 });
// Access JSON data
console.log(data.name); // "John"
JSON in APIs
Most APIs send and receive JSON. When you make a request, the response is usually JSON:
fetch('https://api.example.com/users')
.then(res => res.json())
.then(data => {
console.log(data); // JSON object
});
JSON Files
JSON files use the .json extension. They're used for configuration, data storage, and more:
{
"name": "my-project",
"version": "1.0.0",
"dependencies": {
"express": "^4.18.0",
"react": "^18.0.0"
}
}
This is a package.json file — every Node.js project has one.
Common Mistakes
- Trailing commas — JSON doesn't allow them
- Single quotes — JSON requires double quotes
- Comments — JSON doesn't support comments
- Undefined — JSON doesn't have undefined, only null
Note: JSON is simple but powerful. Master it early — you'll use it in every web application you build.