What is JSON?
JSON stands for JavaScript Object Notation. It is a lightweight, text-based data interchange format that is easy for humans to read and write and easy for machines to parse and generate.
JSON was derived from JavaScript but is completely language-independent. Every major programming language — Python, Java, Go, Ruby, PHP, C#, Rust, Swift — has built-in support for parsing and generating JSON.
JSON was standardised in RFC 8259 (2017) and ECMA-404.
It replaced XML as the dominant data format for web APIs because it is simpler, less verbose, and directly maps to data structures found in every programming language.
JSON Syntax Rules
JSON has a small, strict set of syntax rules. Violating any of them creates a JSON syntax error.
- check_circle
Data is in key/value pairs
Keys must be strings in double quotes. Values can be any JSON data type.
- check_circle
Data is separated by commas
Every item in an object or array must be separated by a comma — except the last one.
- check_circle
Curly braces hold objects
{ } define a JSON object — an unordered collection of key/value pairs.
- check_circle
Square brackets hold arrays
[ ] define a JSON array — an ordered list of values.
- check_circle
Strings must use double quotes
Single quotes are not allowed. All strings — keys and values — need double quotes.
- check_circle
No trailing commas
Unlike JavaScript, JSON does not allow a comma after the last element.
- check_circle
No comments
JSON does not support // or /* */ comments. They cause a syntax error.
JSON Data Types
JSON supports exactly six data types. Every value in JSON must be one of these:
| Type | Example | Notes |
|---|---|---|
| String | "Hello, world!" | Must use double quotes. Escape special characters with \. |
| Number | 42, 3.14, -17 | Integer or float. No NaN, Infinity, or hex literals. |
| Boolean | true, false | Lowercase only. True and False are invalid. |
| Null | null | Represents absence of value. Lowercase only. |
| Object | {"key": "value"} | Unordered collection of key/value pairs in { }. |
| Array | [1, 2, 3] | Ordered list of values in [ ]. Can mix types. |
JSON Objects
A JSON object is an unordered set of key/value pairs, wrapped in curly braces { }. Keys are always strings in double quotes.
{
"firstName": "Alice",
"lastName": "Johnson",
"age": 28,
"isActive": true,
"score": 98.5,
"nickname": null
}Each key/value pair is separated by a colon : and pairs are separated by commas. No comma after the last pair.
JSON Arrays
A JSON array is an ordered collection of values wrapped in square brackets [ ]. Array elements can be any JSON type and can mix types.
{
"tags": ["javascript", "api", "json"],
"scores": [98, 87, 92, 100],
"mixed": [1, "hello", true, null],
"empty": []
}Nested JSON
JSON objects and arrays can be nested to any depth. This is how real-world API responses are structured:
{
"user": {
"id": 12345,
"name": "Alice",
"address": {
"city": "San Francisco",
"country": "US"
},
"orders": [
{ "id": "ord_001", "total": 79.99 },
{ "id": "ord_002", "total": 149.50 }
]
}
}Use our JSON viewer to explore deeply nested structures interactively.
JSON vs JavaScript Objects
JSON looks like JavaScript but has stricter rules. These differences cause the most common JSON syntax errors:
| Feature | JavaScript | JSON |
|---|---|---|
| String quotes | Single or double: 'hello' or "hello" | Double quotes only: "hello" |
| Object keys | Can be unquoted: {name: "Alice"} | Must be quoted: {"name": "Alice"} |
| Trailing commas | Allowed: [1, 2, 3,] | Not allowed: [1, 2, 3] |
| Comments | Allowed: // and /* */ | Not allowed |
| undefined | Valid value | Not a valid type |
| NaN / Infinity | Valid values | Not valid — use null instead |
| Functions | Allowed as values | Not allowed |
Common JSON Errors
See the full JSON errors guide with before/after fix examples. The three most frequent errors are:
Trailing comma
{"name": "Alice",}{"name": "Alice"}Unquoted keys
{name: "Alice"}{"name": "Alice"}Single-quoted strings
{'name': 'Alice'}{"name": "Alice"}Where JSON is Used
REST & GraphQL APIs
Nearly every modern web API sends and receives data as JSON.
Configuration Files
package.json, tsconfig.json, .eslintrc — all use JSON format.
Databases
MongoDB, Elasticsearch, PostgreSQL JSONB — store documents as JSON.
Data Exchange
Between microservices, message queues, and event-driven systems.
Mobile Apps
iOS and Android apps consume JSON from APIs and store JSON in local storage.
CLI Tools
npm, yarn, docker compose, and hundreds of CLI tools use JSON for config.