What is JSON? A Complete Beginner's Guide
JSON (JavaScript Object Notation) is the lingua franca of the modern web — the format nearly every API, configuration file, and NoSQL database speaks. This guide walks through the syntax, the six data types, and how JSON is actually used.
What is JSON?
JSON is a text-based format for representing structured data. It was derived from JavaScript's object-literal syntax, but it's language-agnostic: nearly every programming language can read and produce JSON.
It was introduced by Douglas Crockford in the early 2000s as a simpler alternative to XML. Today it's an international standard (ECMA-404 / RFC 8259) and the default payload format for REST APIs, GraphQL, and most web services.
JSON syntax basics
JSON has two structures: objects (key/value maps wrapped in curly braces) and arrays (ordered lists wrapped in square brackets). Keys must be double-quoted strings; values can be any of the six data types.
{
"name": "Alice",
"age": 30,
"active": true,
"roles": ["admin", "editor"],
"address": {
"city": "San Francisco",
"zip": "94102"
},
"metadata": null
}Note the rules: keys use double quotes (single quotes are invalid), items are separated by commas, and there's no trailing comma after the last item.
The six data types
JSON supports exactly six data types. Understanding them is the foundation of working with any JSON.
string — text in double quotes, e.g. "hello". number — integers or decimals, e.g. 42 or 3.14. boolean — true or false (unquoted). null — an explicit empty value. object — a { } map of key/value pairs. array — a [ ] ordered list.
That's it. JSON has no dates, no functions, no undefined — those have to be encoded as strings or omitted. This minimalism is what makes JSON so universally interoperable.
Where JSON is used
APIs: nearly every REST and GraphQL endpoint exchanges JSON. Configuration: package.json, tsconfig.json, and countless tool configs are JSON. Databases: MongoDB, CouchDB, and PostgreSQL's JSONB store documents as JSON. Data exchange: the wire format between server and browser in modern web apps.
FAQ
- Is JSON the same as a JavaScript object?
- No. A JavaScript object literal can contain functions, comments, single-quoted strings, and trailing commas. JSON is stricter: double-quoted keys, no functions, no comments. Every valid JSON document is a valid JavaScript expression, but not vice versa.
- Can JSON contain comments?
- Standard JSON cannot. Some tools (like VS Code's JSONC) allow comments as an extension, but a strict parser like JSON.parse() will reject them. If you need comments, consider JSON5, YAML, or JSONC.
- What's the difference between JSON and XML?
- JSON is lighter (no closing tags), maps directly to native data structures, and is faster to parse. XML is more verbose but supports attributes, namespaces, and schemas natively. JSON won for APIs; XML survives in document-heavy domains.
Related articles
The History of JSON: From 2000 to Industry Standard →
Trace JSON from Douglas Crockford's idea in 2001, through Yahoo's adoption, to becoming the ECMA-404 standard that powers 90% of modern APIs.
The Complete JSON Schema Guide (Draft 7) →
JSON Schema is the standard for describing and validating JSON structure. Learn the core keywords, build a real API schema, and apply best practices.
JSON Examples in 7 Languages: JavaScript, Python, Go, Rust, PHP, Java, C# →
Production-ready JSON parsing and serialization examples across seven languages — with error handling and best practices.