What is JSON?
A complete guide to the world's most popular data interchange format
JSON in a Nutshell
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. It's the standard way applications send and receive data over the internet. When you use a weather app, scroll social media, or make an online purchase, JSON is almost certainly carrying the data between the server and your device.
JSON was derived from JavaScript but is completely language-independent. Every major programming language — Python, Java, Go, C#, Ruby, PHP, Rust, Swift — can read and write JSON. It was specified by Douglas Crockford in the early 2000s and is defined in RFC 8259 and ECMA-404.
JSON Syntax
JSON has just two structures:
- Objects — unordered collections of key/value pairs, wrapped in curly braces
{} - Arrays — ordered lists of values, wrapped in square brackets
[]
A JSON value can be:
- String —
"hello world"(always double quotes) - Number —
42,3.14,-1,1.5e10 - Boolean —
trueorfalse - null — represents an empty value
- Object — nested objects
- Array — nested arrays
{
"name": "Alice",
"age": 30,
"isActive": true,
"email": null,
"skills": ["JavaScript", "Python", "Go"],
"address": {
"city": "San Francisco",
"zip": "94102"
}
}Why JSON Became the Standard
Before JSON, XML was the dominant data format for web APIs. JSON won because it's:
- Simpler — no closing tags, no attributes, no DTDs. A JSON object is 30-50% smaller than the equivalent XML.
- Native to JavaScript — browsers can parse JSON with a single
JSON.parse()call. No external libraries needed. - Human-readable — developers can scan JSON and understand the data structure immediately.
- Universal — every language has built-in JSON support. No special parser libraries required.
By 2015, JSON had completely replaced XML for web APIs. Today, over 70% of all public APIs use JSON as their primary format.
Common JSON Use Cases
- REST APIs — almost every REST API sends and receives JSON. When you call
GET /api/users, the response is JSON. - Configuration files —
package.json(Node.js),tsconfig.json(TypeScript),.eslintrc.json, VS Code settings — all JSON. - Databases — MongoDB stores documents as BSON (binary JSON). PostgreSQL has native
jsonbcolumns. - Message queues — Kafka, RabbitMQ, and SQS commonly transmit JSON messages.
- Local storage — browsers store data with
localStorage.setItem('key', JSON.stringify(data)).
JSON Rules to Remember
- Keys must be strings in double quotes —
"name", notnameor'name'. - No trailing commas —
{"a": 1,}is invalid JSON. - No comments — JSON does not support
//or/* */comments. - No single quotes — strings must use double quotes.
- No undefined — use
nullinstead. - Numbers can't have leading zeros —
07is invalid, use7.
JSON in Different Languages
JavaScript
const data = JSON.parse(text) const text = JSON.stringify(data)
Python
import json data = json.loads(text) text = json.dumps(data)
Go
json.Unmarshal([]byte(text), &data) text, _ := json.Marshal(data)
Java
new ObjectMapper() .readValue(text, Map.class)
JSON vs Other Formats
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Readability | Good | Verbose | Best |
| File size | Small | Large | Small |
| Comments | No | Yes | Yes |
| Schema | JSON Schema | XSD/DTD | No standard |
| API usage | Dominant | Legacy | Rare |
| Config files | Common | Rare | Very common |
Want a deeper comparison? Read our JSON vs YAML vs XML guide.