What is JSON? A Complete Beginner's Guide (2026)
This is the post I wish I'd had when I was learning JSON. If you've seen the format in passing — in an API response, a config file, a tutorial — and want a single page that explains what it actually is, why it took over the web, and what trips people up, this is that page.
What is JSON?
JSON — short for JavaScript Object Notation — is a lightweight, text-based format for representing structured data. It looks like this:
{
"name": "Ada Lovelace",
"born": 1815,
"skills": ["math", "computing"],
"active": true
}
You can read it. A computer can read it. Crucially, every major programming language — Python, Java, Go, Rust, C#, Ruby, Swift, PHP, even older ones like COBOL via libraries — can read it. That universality is the whole point. JSON exists so that two systems written in different languages, on different machines, possibly built decades apart, can exchange data without arguing about format.
It is the dominant format of the web. When you log in to a website, click "save" in a single-page app, or refresh your social media feed, JSON is almost certainly travelling between your browser and a server somewhere in the background.
Where JSON came from
JSON was specified by Douglas Crockford in the early 2000s, drawing on JavaScript's object literal syntax — hence the name. The genius of the format is what it left out: no namespaces, no schemas, no type tags, no comments. A JSON document is just six possible value types arranged in trees, and that minimalism is what allowed every language to implement a parser quickly and consistently.
The first major systems to adopt it were AJAX-based web apps in 2005-2006, which preferred JSON over the era's dominant data format, XML. JSON was smaller on the wire, faster to parse in a browser, and easier on the eyes. Within a few years, REST APIs returning JSON became the default for web services, and by 2013 the format was standardised as RFC 7159 (later updated to RFC 8259).
Today, JSON underpins:
- Virtually every public REST API (Stripe, GitHub, OpenAI, Slack, Twitter/X)
- Configuration files in JavaScript and TypeScript projects (
package.json,tsconfig.json) - Document databases like MongoDB, Couchbase and Firebase
- Application logs in structured-logging systems
- Browser storage (
localStoragevalues are typically JSON-stringified) - Kubernetes manifests (via YAML, which is a superset of JSON)
Why JSON beat XML
To understand why JSON took over, look at the same data in both formats.
XML:
<user>
<name>Ada Lovelace</name>
<born>1815</born>
<skills>
<skill>math</skill>
<skill>computing</skill>
</skills>
</user>
JSON:
{
"name": "Ada Lovelace",
"born": 1815,
"skills": ["math", "computing"]
}
Both convey the same information, but JSON wins on three axes that matter in practice. It is shorter (roughly half the bytes for typical web payloads). It maps directly to in-memory data structures in most languages — a JSON object becomes a dictionary or hash map, a JSON array becomes a list, with no XML-style ambiguity about whether an empty element means null or empty string. And it is easier to read when you are debugging at 2 a.m. with no documentation.
XML still has a role in document-heavy domains (publishing, finance, healthcare), but for general data exchange, JSON has won decisively.
JSON syntax in 60 seconds
JSON has exactly six value types:
- String —
"hello"(must use double quotes — single quotes are not legal) - Number —
42,3.14,-1e10(noNaN, noInfinity, no leading zeros) - Boolean —
trueorfalse(lowercase only) - Null —
null(lowercase) - Array —
[1, 2, 3](ordered, can mix types) - Object —
{"key": "value"}(unordered key/value pairs, keys are always strings)
Arrays and objects can be nested arbitrarily deep, which is how JSON represents complex structures like trees or graphs:
{
"user": {
"name": "Ada",
"address": {
"city": "London",
"country": "UK"
},
"orders": [
{ "id": 1, "total": 99.99 },
{ "id": 2, "total": 149.50 }
]
}
}
That's the whole format. There are no other constructs to learn — no type system, no inheritance, no namespaces. The simplicity is the feature.
Common pitfalls
If you're new to JSON, these are the mistakes you'll make:
- Comments. JSON does not allow
//or/* */comments. Configuration files that need comments often use JSONC (used by VS Code's settings) or JSON5, both of which require a special parser. Strict JSON is comment-free by design.
- Trailing commas.
{"a": 1,}looks fine because most programming languages allow it, but JSON does not. Remove the comma before any closing brace or bracket.
- Unquoted keys.
{name: "Ada"}is a JavaScript object literal, not JSON. Every key must be a double-quoted string.
- Single quotes.
{'name': 'Ada'}is JavaScript, not JSON. Both keys and string values must use double quotes.
- Unescaped newlines in strings. A literal newline inside a string value is illegal. Use
\ninstead.
- Smart quotes. Curly
"like this"from a word processor look identical to ASCII quotes but break parsing instantly. Always paste through a plain-text intermediate.
NaN,Infinityand-Infinity. JavaScript supports them, JSON does not. Serialize them asnullor as strings.
Use JSONNeat's validator to catch any of these — it reports the exact line and column of the first error.
When to use JSON
JSON is ideal for:
- REST APIs — request and response bodies, by far the most common use case
- Configuration files — when you don't need comments (otherwise consider YAML or TOML)
- Browser-to-server communication —
fetch().then(r => r.json())is one line - NoSQL document storage — MongoDB, DynamoDB, Firestore all store JSON natively
- Frontend state serialization — Redux DevTools, localStorage, query string state libraries
- Inter-process communication — Electron IPC, language server protocol, debugger protocols
When to use something else
JSON has real weaknesses:
- Binary data. JSON is text. To embed binary, you must Base64-encode it, growing the data by ~33%. For payloads dominated by binary blobs, use a binary format like Protocol Buffers, MessagePack or Avro.
- Very large datasets. Parsing JSON requires loading the whole document into memory. For multi-gigabyte data, JSON Lines (one record per line) or columnar formats like Parquet scale much better.
- Files humans edit by hand frequently. YAML and TOML are easier on the eyes for configuration. JSON's required punctuation gets tedious.
- Strongly typed schemas with cross-language code generation. Protocol Buffers and Avro give you generated types in every supported language, plus efficient binary wire formats. Use these for high-throughput internal services.
- Streaming over the wire. JSON is all-or-nothing. To process records as they arrive, switch to NDJSON / JSON Lines, or use a streaming parser like stream-json or oboe.js.
JSON vs JavaScript objects
A point of constant confusion for beginners: JSON looks like a JavaScript object literal, but they are not the same thing.
JavaScript object literal — only valid inside JavaScript code:
const user = { name: 'Ada', age: 200 }
JSON — a *string* containing a representation of data:
const json = '{"name": "Ada", "age": 200}'
const user = JSON.parse(json)
JSON is always a string. JavaScript objects are in-memory values. The conversion between them happens via JSON.parse (string → object) and JSON.stringify (object → string). Mixing these up is one of the most common bugs in early-career JavaScript.
A small example end-to-end
Here is a complete client/server exchange using JSON:
Client (JavaScript):
const response = await fetch('/api/user/42')
const user = await response.json()
console.log(user.name) // "Ada Lovelace"
Server (Python with Flask):
@app.route('/api/user/<int:user_id>')
def get_user(user_id):
user = db.fetch_user(user_id)
return jsonify({
'name': user.name,
'born': user.born,
'skills': user.skills
})
Two languages, two runtimes, one data format. Neither side cares what language the other is using. That's JSON's superpower.
Tools to keep handy
- JSONNeat formatter — pretty-print and validate any JSON in your browser
- JSONNeat validator — pinpoint syntax errors by line and column
- JSONNeat minifier — strip whitespace for wire payloads
- jq — a command-line JSON processor for querying and transforming data
- VS Code — has built-in JSON formatting and schema support
Where to go next
Once the rules feel obvious, the next two topics that actually paid off for me were JSON Schema (so you can describe and validate the *shape* of a document, not just whether it parses) and JSON in JavaScript (the everyday JSON.parse and JSON.stringify patterns and the surprising things that don't survive a round-trip).
The whole format takes about an afternoon to internalise. After that you'll use it almost every day. Have fun.
Related tools: JSON formatter, validator, minifier.