JSON Format Explained
A complete, practical guide to the JSON format — what it is, how it's structured, its six data types, objects vs arrays, nesting, formatting rules, and how it compares to XML and YAML.
Table of Contents
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. It was originally derived from JavaScript object literal syntax but is now completely language-independent. JSON is defined by RFC 8259 and is the de-facto standard format for REST APIs, configuration files, and data storage.
JSON is designed to be easy for humans to read and write, and easy for machines to parse and generate. A JSON document is always valid UTF-8 text, starts with either { (for an object) or [ (for an array), and contains only the six JSON data types.
Use the JSON Formatter to pretty-print and validate any JSON, or the JSON Examples page to see real-world JSON samples you can copy and use.
JSON Data Types
JSON supports exactly six value types. Any valid JSON value must be one of these — no more, no less.
| Type | Example | Notes |
|---|---|---|
| String | "Hello, World!" | Must use double quotes. Supports escape sequences like \n, \t, \\. |
| Number | 42, 3.14, -7, 1e10 | No distinction between integers and floats. No NaN or Infinity. |
| Boolean | true, false | Lowercase only. "True" and "False" are invalid. |
| Null | null | Represents the intentional absence of a value. Lowercase only. |
| Object | {"key": "value"} | Unordered collection of key-value pairs. Keys must be strings. |
| Array | [1, "two", true, null] | Ordered list. Can mix any value types. |
Note: JSON has no date type, no function type, and no undefined type. Dates are typically represented as ISO 8601 strings.
JSON Objects
A JSON object is an unordered collection of key-value pairs enclosed in curly braces {}. Each key is a string in double quotes, followed by a colon, followed by a value. Pairs are separated by commas — but no trailing comma is allowed after the last pair.
{
"name": "Alice",
"age": 30,
"isAdmin": false,
"score": 99.5,
"address": null
}Key rules for JSON objects:
- All keys must be strings in double quotes
- Keys should be unique within an object (duplicate keys are technically legal but behavior is undefined)
- The order of keys is not guaranteed
- Values can be any of the six JSON types
- No trailing comma after the last key-value pair
JSON Arrays
A JSON array is an ordered list of values enclosed in square brackets []. Values are separated by commas. Arrays can contain any mix of JSON value types.
["apple", "banana", "cherry"]
[1, 2, 3, 4, 5]
[true, false, null, 42, "mixed"]
[
{"name": "Alice"},
{"name": "Bob"}
]Key rules for JSON arrays:
- Values are indexed starting at 0
- Order is preserved
- Can mix any JSON value types in one array
- No trailing comma after the last element
Nested JSON
JSON can be nested to arbitrary depth — objects can contain arrays, arrays can contain objects, and objects can contain objects. This is what makes JSON powerful enough to represent complex real-world data structures.
{
"user": {
"id": 101,
"name": "Alice",
"roles": ["admin", "editor"],
"address": {
"city": "New York",
"zip": "10001"
},
"tags": [
{"id": 1, "label": "premium"},
{"id": 2, "label": "verified"}
]
}
}Use the JSON Viewer to explore nested JSON as a collapsible tree, making it much easier to navigate deeply nested structures.
JSON Formatting & Whitespace
JSON ignores whitespace (spaces, tabs, newlines) outside of string values. This means minified JSON and pretty-printed JSON are semantically identical — parsers treat them the same.
Pretty-Printed (readable)
{
"name": "Alice",
"age": 30
}Minified (compact)
{"name":"Alice","age":30}Use pretty-printed JSON when debugging or in config files. Use minified JSON when sending data over a network to reduce payload size.
JSON vs XML vs YAML
JSON, XML, and YAML are all data serialization formats. Here's how they compare for common use cases:
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Human readable | ✓ Yes | ~ Verbose | ✓ Very readable |
| Supports comments | ✗ No | ✓ Yes | ✓ Yes |
| Data types | 6 built-in types | All strings by default | Rich type system |
| Parsing complexity | Simple | Complex | Moderate |
| File size | Compact | Verbose | Compact |
| REST API default | ✓ Yes (standard) | Legacy | ✗ Rarely |
| Config files | ✓ Common | Less common | ✓ Very common |
| Schema support | JSON Schema | XSD, DTD | JSON Schema compatible |
Common JSON Use Cases
REST APIs
JSON is the standard request/response format for virtually all modern REST APIs. Every major language has built-in JSON parsing support.
Configuration Files
package.json, tsconfig.json, .prettierrc — JSON is widely used for tool configuration because it's easy to parse and validate.
Data Storage
NoSQL databases like MongoDB store documents as BSON (Binary JSON). PostgreSQL has native JSON/JSONB column types.
Data Exchange
JSON is used to exchange data between services, frontends, backends, mobile apps, and third-party integrations.
Web APIs & AJAX
fetch() and XMLHttpRequest send and receive JSON. JSON.parse() and JSON.stringify() are built into every browser.
Event Logging
Structured logs in JSON format can be queried, filtered, and analyzed by log aggregation tools like Datadog, Splunk, and ELK.
FAQ – JSON Format
What is the JSON format?expand_more
JSON (JavaScript Object Notation) is a lightweight text-based data format. JSON data is structured as key-value pairs (objects) or ordered lists (arrays). It uses human-readable text and is the standard format for REST APIs and configuration files.
What are the 6 JSON data types?expand_more
JSON supports exactly 6 data types: string (text in double quotes), number (integer or floating point), boolean (true or false), null, object (key-value pairs in curly braces), and array (ordered list in square brackets).
What is the difference between a JSON object and a JSON array?expand_more
A JSON object is an unordered collection of key-value pairs wrapped in curly braces: {"name": "Alice"}. A JSON array is an ordered list of values wrapped in square brackets: ["Alice", "Bob", "Carol"]. Objects use string keys to access values; arrays use numeric indexes.
Is JSON the same as JavaScript?expand_more
No. JSON is a data format that was inspired by JavaScript object literal syntax, but they are different. JSON is stricter: it requires double quotes on all strings and keys, does not allow trailing commas, undefined values, or functions. JSON is language-independent and supported in virtually every programming language.
What file extension does JSON use?expand_more
JSON files use the .json file extension and the MIME type application/json. Some tools use .jsonl (JSON Lines, one JSON object per line) or .json5 (JSON5, a superset of JSON that allows comments).
Part of the JSON Toolkit
Explore All JSON Tools
Free online tools for every JSON task — format, validate, convert, compare, and more.