What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. It is based on a subset of JavaScript syntax but is language-independent.
Quick Facts
| Full Name | JavaScript Object Notation |
|---|---|
| Created | 2001 by Douglas Crockford |
| Specification | Official Specification |
How JSON Works
JSON uses a simple structure of key-value pairs and ordered lists to represent data. Objects are enclosed in curly braces {} with comma-separated key-value pairs, where keys are strings in double quotes. Arrays are enclosed in square brackets [] with comma-separated values. JSON supports six data types: strings, numbers, booleans (true/false), null, objects, and arrays. Unlike XML, JSON has no closing tags, making it more compact and faster to parse.
Key Characteristics
- Human-readable text format with minimal syntax
- Language-independent but uses conventions familiar to C-family languages
- Supports nested data structures (objects within objects, arrays within arrays)
- No support for comments in the official specification
- Strict syntax rules - keys must be double-quoted strings
- Smaller file size compared to XML for equivalent data
Common Use Cases
- API responses and requests in web services (REST APIs)
- Configuration files for applications and tools
- Data storage in NoSQL databases like MongoDB
- Data exchange between client and server in web applications
- Package management files (package.json, composer.json)
Example
{
"name": "John Doe",
"age": 30,
"isActive": true,
"email": null,
"skills": ["JavaScript", "Python", "SQL"],
"address": {
"city": "New York",
"country": "USA"
}
}