What Is JSON? A Complete Guide for Developers
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging structured data. If you have called a REST API, edited a config file, or looked at a package.json, you have already used it. JSON has become the default way services pass data around because it is compact, human-readable, and every major language can parse it.
This guide covers what JSON actually is: its syntax, its data types, how it maps to objects in code, where it shows up in real work, and the handful of mistakes that cause most JSON bugs.
The shape of JSON
JSON is built from two structures that nest inside each other:
- Objects are unordered sets of key/value pairs wrapped in curly braces. Keys are always strings in double quotes.
- Arrays are ordered lists of values wrapped in square brackets.
A small example with both:
{
"name": "Ada Lovelace",
"active": true,
"roles": ["admin", "engineer"],
"address": { "city": "London", "zip": "SW1A" }
}
That is the whole idea: objects hold named fields, arrays hold sequences, and either can contain the other to any depth. To read a nested payload quickly, paste it into a JSON viewer and expand the branches you care about, or format it for a clean indented layout.
JSON data types
JSON allows exactly six value types. Knowing them explains most “why won’t this parse” questions.
| Type | Example | Notes |
|---|---|---|
| String | "hello" |
Always double quotes, never single |
| Number | 42, -3.14, 1e5 |
No leading zeros, no NaN or Infinity |
| Boolean | true, false |
Lowercase only |
| Null | null |
Lowercase; means “no value” |
| Object | { "a": 1 } |
Keys must be quoted strings |
| Array | [1, 2, 3] |
Ordered, can mix types |
Notice what is missing: no dates, no comments, no functions, no undefined. Dates are usually sent as ISO 8601 strings like "2026-01-31T09:00:00Z", and there is no comment syntax at all.
How JSON maps to code
JSON looks like a JavaScript object literal, but it is a text format, not code. You convert between the two with a parser.
- JavaScript:
JSON.parse(text)turns a JSON string into a value;JSON.stringify(value)does the reverse. The JSON stringify tool mirrors that second step in the browser. - Python:
json.loads(text)returns a dict or list;json.dumps(value)serializes it back. - Most other languages ship an equivalent in their standard library.
Because parsing is where malformed data first fails loudly, it is worth validating input before you rely on it. The JSON parser reports the exact line and column of a syntax error, which is faster than reading a stack trace.
Where JSON is used
JSON is everywhere data moves between systems:
- REST and GraphQL APIs send and receive JSON request and response bodies.
- Config files like
package.json,tsconfig.json, and countless tool settings. - NoSQL databases such as MongoDB store documents that are JSON in all but name.
- Log pipelines emit structured JSON lines so machines can query them.
- Browser storage and messaging, where objects are stringified to travel as text.
Its reach is the reason a good JSON formatter and minifier are daily-driver tools: you format to read during development, and minify to shrink payloads in production.
Why JSON became the default
JSON did not win by committee. It won because it removed friction. It grew out of JavaScript object syntax, so anything a browser fetched could be turned into usable data with a single JSON.parse call, no library required. That native fit made it the obvious choice for the AJAX era, and every other language followed with a built-in parser.
Compared with XML, the format it largely displaced, JSON is dramatically lighter. The same data in JSON is typically far smaller than in XML because there are no closing tags and no attribute ceremony, which means less bandwidth per request and faster parsing on both ends. It is also easier to read: an object with a few keys looks almost identical to the data structure it represents, where XML wraps every value in angle brackets. The trade-off is that JSON is deliberately minimal. It has no schema built in, no comments, and no namespaces, so ecosystems that need those add them on top (JSON Schema for validation, for example). For the common case of moving structured data between a server and a client, that minimalism is exactly why it stuck. For a fuller side-by-side of the three main data formats, see JSON vs XML vs YAML.
The mistakes that cause most JSON bugs
Almost every “invalid JSON” error comes down to one of these:
- Single quotes. JSON requires double quotes on keys and string values.
{'a': 1}is valid JavaScript but invalid JSON. - Trailing commas. A comma after the last item, like
[1, 2,], is allowed in JavaScript arrays but rejected by JSON. - Unquoted keys.
{a: 1}must be{"a": 1}. - Comments. JSON has none; strip
//and/* */before parsing. - Getting HTML instead of JSON. When a request returns an error page, parsing fails at position 0 on the
<of<!DOCTYPE html>. That specific case has its own fix guide.
When something will not parse, do not eyeball it. Run it through the JSON parser or clean up stray characters with JSON escape, and the problem usually becomes obvious in seconds.
Frequently asked questions
Is JSON the same as a JavaScript object?
No. A JavaScript object is code held in memory; JSON is a text format that represents such data. JSON is stricter, too: it requires double-quoted keys and forbids comments, functions, and undefined.
Can JSON store dates?
Not as a native type. Dates are sent as strings, almost always in ISO 8601 format, and parsed back into date objects by your code.
What is the difference between JSON and XML?
Both carry structured data, but JSON is lighter and maps directly to objects and arrays, while XML uses nested tags and attributes. Most web APIs prefer JSON for its smaller size and simpler parsing.
How do I check if my JSON is valid?
Paste it into a validator such as the JSON parser. A well-formed document renders cleanly; a malformed one is flagged at the exact character where it breaks.