What is JSON? JSON (JavaScript Object Notation) is a text format for structured data, and it is the most common way to move data around the web. Weather apps, microservices and config files all use it.
This guide covers where JSON came from, its six value types, what a real document looks like, and how to read and validate one. You only need to know what a text file and a key-value pair are.
What is JSON?
JSON stands for JavaScript Object Notation. It is a text format that stores structured data as key-value pairs and ordered lists. Since it is plain text, people can read it, files can store it, and networks can carry it.
JSON builds all data from two structures. Objects are collections of named values, written with curly braces {}. Arrays are ordered lists of values, written with square brackets []. Nest them and you can describe a user profile, a shopping cart or a sensor reading.
Here is a small example, an object with two fields:
{
"name": "Ada",
"age": 36
}JSON is a *format*, not a programming language. You can't write logic in it. It describes data, and a program reads it (parsing) or writes it (serializing).
A short history of JSON
Douglas Crockford specified JSON in the early 2000s. Developers were already sending data between browser and server as a subset of JavaScript object-literal syntax, because browsers could turn that text back into objects cheaply. Crockford wrote down the rules, named the format and published it at json.org.
At the time, XML was the main data interchange format. It was verbose, and parsing it in a browser was awkward. JSON offered the same nesting with far less syntax, and it mapped straight onto native data structures. It spread with AJAX web apps in the mid-2000s.
JSON's standards do not depend on JavaScript. It is defined by ECMA-404 and RFC 8259, and every mainstream language ships a JSON parser. Python, Go, Rust, Java and C# all read and write it.
The six JSON value types
Every value in a JSON document has one of six types. Learn these and you know most of the format. For edge cases, see the JSON data types guide.
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Text in double quotes only. Supports escapes like \n and \". |
| Number | 42, -3.14, 2.5e6 | One numeric type. No int/float split, and no NaN or Infinity. |
| Boolean | true, false | Lowercase only. |
| Null | null | An empty or missing value. |
| Object | { "key": value } | String-keyed pairs. Treated as unordered. |
| Array | [1, 2, 3] | Ordered list. Values can mix types. |
Rules that trip up beginners
- Keys and string values must use double quotes. Single quotes are invalid JSON.
- There are no trailing commas.
[1, 2, 3,]is a syntax error. - Comments are not allowed in standard JSON.
- Numbers can't have leading zeros or a bare decimal point at either end.
.5,5.and01are all invalid.
An annotated JSON example
This document uses all six value types. It describes a user with a nested object and an array:
{
"id": 1042,
"username": "ada.lovelace",
"isActive": true,
"middleName": null,
"roles": ["admin", "editor"],
"profile": {
"displayName": "Ada Lovelace",
"loginCount": 87,
"lastLogin": "2026-07-01T09:30:00Z"
},
"tags": []
}From the top: id is a number, username is a string, isActive is a boolean, and middleName is null because the user has no middle name. roles is an array of strings. profile is a nested object, and objects can nest to any depth. lastLogin is a string because JSON has no date type. Timestamps are usually stored as ISO 8601 strings. tags is an empty array, which is valid.
Where JSON is used
JSON is the default data format in most modern software. You will see it most often in these four places:
Web APIs
Most REST APIs send and receive JSON. The server answers requests with a JSON body, and apps often submit forms as JSON. The Content-Type: application/json header marks this.
Configuration files
npm (package.json), TypeScript (tsconfig.json) and many other tools store settings as JSON. It handles nested options and is still easy to edit by hand.
Logs and events
Structured logging systems write one JSON object per line, a format called NDJSON. Machines can then filter and query logs by field instead of grepping raw text.
NoSQL databases
Document databases like MongoDB store records as JSON-like documents. Each record can have its own nested structure, with no fixed table schema.
JSON vs XML: why JSON won
Both formats store nested, structured data as text, but they make different trade-offs. Here is the same data in XML:
<user>
<name>Ada</name>
<age>36</age>
</user>The JSON version, {"name": "Ada", "age": 36}, holds the same information in far fewer characters. It also maps straight onto the objects and arrays that programming languages already use. XML is still a good fit for documents that need attributes, namespaces, mixed content or XSD validation. For API payloads and config, JSON is usually the lighter choice. See JSON vs XML for the full comparison.
How to read and validate JSON
JSON syntax is strict, so one misplaced comma or missing quote breaks the whole document. A validator is the fastest way to find the problem. It parses the text and reports where the first error is.
In code, "reading" JSON means parsing the text into a native data structure. JavaScript has this built in:
const text = '{"name": "Ada", "roles": ["admin", "editor"]}';
// Parse JSON text into a JavaScript object
const user = JSON.parse(text);
console.log(user.name); // "Ada"
console.log(user.roles[0]); // "admin"
// Serialize a JavaScript object back into JSON text
const output = JSON.stringify(user, null, 2);
console.log(output);JSON.parse turns text into an object. JSON.stringify does the reverse, and the 2 argument indents the output by 2 spaces. Every major language has an equivalent. See Working with JSON in Python for Python's json module. If a parse fails, a validator shows you *where*, and the fix is usually quick.