What Is JSON? Syntax Rules, Data Types and Examples
· 5 min read
JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging structured data, built from key/value objects and ordered arrays. It is language-independent, readable by humans and parsed by virtually every programming language, which is why most web APIs and many config files use it.
JSON is defined by two matching standards, IETF RFC 8259 and ECMA-404. Its grammar is small enough to learn in ten minutes. To experiment while you read, paste any example below into the JSON formatter to indent it and see exactly where it breaks if you get a rule wrong.
A JSON example
{
"id": 1024,
"name": "Ada Lovelace",
"email": "ada@example.com",
"verified": true,
"score": 98.5,
"manager": null,
"roles": ["admin", "editor"],
"address": {
"city": "London",
"postcode": "W1A 1AA"
}
}The outer { } is an object. Each line inside is a key (always a double-quoted string), a colon, and a value. roles holds an array and address holds another object, which is how JSON represents nested data.
The 6 JSON data types
| Type | Example | Rules |
|---|---|---|
| String | "hello" | Double quotes only. Escape " and \ with a backslash; control characters must be escaped (\n, \t, \u00e9). |
| Number | 42, -3.14, 6.02e23 | Decimal only. No leading zeros (07), no leading +, no hex, no NaN or Infinity. No separate integer and float types. |
| Boolean | true, false | Lowercase only. |
| Null | null | Lowercase. Means "no value". |
| Object | {"a": 1, "b": 2} | Unordered set of name/value pairs in braces. Keys must be strings and should be unique. |
| Array | [1, "two", null] | Ordered list in brackets. Values can be of mixed types. |
There is no date, binary or undefined type. Dates are normally sent as ISO 8601 strings ("2026-11-02T09:30:00Z") and binary data as Base64 strings; the receiving program converts them.
JSON syntax rules
- Data is name/value pairs:
"name": value. - Pairs and array items are separated by commas, with no trailing comma after the last one.
- Keys and strings use double quotes. Single quotes are invalid.
- Objects use
{ }, arrays use[ ]. - No comments of any kind (
//or/* */). true,falseandnullare lowercase and unquoted.- Whitespace between tokens (spaces, tabs, line breaks) is ignored, so the same data can be minified or indented.
- A JSON text can be any value at the top level, not only an object or array;
"hi"and42are valid JSON documents under RFC 8259.
Breaking any of these produces a parse error such as "Unexpected token". The most frequent culprits, with fixes, are listed in common JSON errors and how to fix them, and the JSON validator points to the exact line and column.
Object vs array: which to use
Object { } | Array [ ] | |
|---|---|---|
| Holds | Named fields | A list of values |
| Access by | Key: user.name | Position: users[0] |
| Order | Not guaranteed by the spec | Preserved |
| Use for | One thing with properties (a user, a config) | Many things of the same kind (users, line items) |
The common pattern is an array of objects: [{"id": 1}, {"id": 2}]. APIs often wrap that in an object so they can add metadata later, for example {"data": [...], "next": "cursor"}.
JSON vs a JavaScript object
JSON syntax was taken from JavaScript object literals, but JSON is a string format and much stricter.
| Feature | JSON | JavaScript object literal |
|---|---|---|
| Key quotes | Required, double quotes | Optional for simple names |
| String quotes | Double only | Single, double or backticks |
| Trailing commas | Not allowed | Allowed |
| Comments | Not allowed | Allowed |
| Values | 6 types only | Any value: functions, undefined, Date, NaN |
| What it is | Text (a string) | An in-memory value |
const text = '{"name":"Ada","age":36}';
const obj = JSON.parse(text); // text -> object
obj.age += 1;
const back = JSON.stringify(obj); // object -> text: '{"name":"Ada","age":37}'Relaxed variants such as JSON5 and JSONC add comments and trailing commas for config files; see JSON vs JSON5 vs JSONC for when those are acceptable.
What JSON is used for
- Web APIs: most REST APIs send and receive JSON bodies.
- Configuration:
package.json,tsconfig.json, VS Code settings, cloud templates. - Data storage and logs: document databases store JSON-like documents; structured logs often use one JSON object per line (NDJSON).
- Data exchange between languages: a Python service and a Go service can share JSON without either knowing the other's types. To get typed code from a sample, generators such as JSON to TypeScript build the interfaces for you.
- LLM structured output: AI models are asked to reply in JSON so programs can read the result.
- Validation contracts: JSON Schema describes which fields and types a document must have.
File extension, MIME type and encoding
- File extension:
.json. - MIME / Content-Type:
application/json. Do not usetext/json, which is unregistered. - Encoding: RFC 8259 requires UTF-8 for JSON exchanged between systems, and a byte order mark must not be added.
- A
.jsonfile is plain text and opens in any text editor; see how to open a JSON file on each platform, or load it into the JSON tree viewer to explore nested data.
A brief history
Douglas Crockford specified and popularized JSON in the early 2000s as a simpler alternative to XML for browser-server communication. It became ECMA-404 in 2013 and an IETF standard track RFC in 2014 (RFC 7159). The current versions, RFC 8259 and the second edition of ECMA-404, were both published in December 2017 and describe the same syntax.
FAQ
What does JSON stand for?
JavaScript Object Notation. The name reflects its origin in JavaScript object literal syntax, but JSON is language-independent.
Is JSON a programming language?
No. JSON is a data format: it describes values but has no variables, logic or functions, so it cannot run.
Is JSON case sensitive?
Yes. Keys are compared exactly, so "Name" and "name" are different keys, and the literals true, false and null must be lowercase.
What is the MIME type for JSON?
application/json, with the .json file extension. JSON exchanged between systems must be encoded as UTF-8.
Can JSON have comments?
No. Standard JSON does not allow comments. Formats such as JSONC and JSON5 add them, but strict JSON parsers will reject the file.

