JSON, short for JavaScript Object Notation, is a lightweight text format for storing and sending structured data. It represents data as key-value pairs, lists, and nested objects in a way that is easy for both people to read and machines to parse. It is the format most web APIs use to exchange information, which is why nearly every developer reads and writes it daily. Despite the name, it is not tied to JavaScript; every common language can parse it. This explainer covers the syntax, why it became the standard, a quick example, and where it is the wrong tool.
What JSON looks like
JSON is built from a few simple pieces: objects wrapped in curly braces holding key-value pairs, arrays wrapped in square brackets holding lists, and values that are strings, numbers, booleans, null, or more objects and arrays. Keys are always quoted strings.
// a small JSON object
{
"name": "Ada",
"active": true,
"roles": ["admin", "editor"],
"profile": { "city": "Lisbon" }
}
That is essentially the whole language. There are no functions, no comments, and no fancy types. The simplicity is the point: it is small enough to learn in minutes and predictable enough to parse anywhere.
Why JSON won
| Factor |
JSON |
XML |
| Readability |
High, minimal syntax |
Verbose, many tags |
| Size |
Compact |
Larger |
| Parsing |
Built into most languages |
Heavier tooling |
| Comments |
Not supported |
Supported |
| Best for |
APIs, config, data exchange |
Documents, legacy systems |
JSON displaced XML for most web data because it is lighter, easier to read, and maps cleanly onto the data structures programmers already use. It is the standard payload for REST APIs and is just as common in GraphQL responses.
A concrete use
When a weather app shows the forecast, it usually calls an API that returns JSON: an object with the temperature, a condition string, and an array of upcoming days. The app parses that JSON into native objects and renders the screen. The same format carries configuration files, log entries, and messages between services. Its flexibility across all these uses is why it is everywhere.
How to work with it
- Learn the six value types. String, number, boolean, null, object, array; that is all there is.
- Quote your keys. Every key is a double-quoted string, and trailing commas are not allowed.
- Use your language parser. Do not parse JSON by hand; every language has a built-in parser.
- Validate untrusted JSON. Check shape before trusting data from an external source.
- Format it for humans when debugging. Pretty-printing makes nested data readable.
What to skip
- Do not put comments in JSON. The format does not allow them; use a different format for commented config.
- Do not use JSON for huge datasets. For very large or streaming data, formats built for that scale better.
- Do not hand-edit deeply nested JSON. A missing brace breaks the whole file; use tooling.
- Do not assume key order matters. Object key order is not guaranteed to be meaningful.
FAQ
Is JSON a programming language?
No. JSON is a data format for storing and transmitting structured data. It has no logic or behavior; it only describes data.
What is the difference between JSON and XML?
Both store structured data, but JSON is lighter, less verbose, and easier to parse, while XML supports comments and richer document features. JSON dominates web APIs; XML lingers in documents and legacy systems.
Can JSON have comments?
No. Standard JSON does not allow comments. If you need commented configuration, a format like YAML or a JSON variant that permits comments is a better fit.
Is JSON only for JavaScript?
No. It originated from JavaScript syntax but is language independent. Every common programming language has a parser for reading and writing JSON.
Where to go next
See how APIs deliver JSON in what a REST API is, explore a flexible query layer in what GraphQL is, and understand the databases that often store it in what NoSQL is.