JSON Examples
Last updated:
JSON supports exactly 6 data types: string, number, boolean (true/false), null, array, and object. All 6 are defined in RFC 8259 and ECMA-404. A flat key-value object like {"name": "Alice", "age": 30} is the most common API shape, while arrays of objects handle lists of 1–10,000+ records. This page covers 12 canonical patterns with copy-paste examples: flat objects, arrays of objects, nested structures up to 4 levels, mixed arrays, pagination envelopes with total and page fields, error responses with HTTP status codes, date strings in ISO 8601 format, null vs absent fields, empty objects and arrays, and real-world API response shapes from REST endpoints.
Format and validate JSON online
Paste any JSON to beautify, validate, and minify it instantly in your browser.
Open JSON FormatterSimple JSON object
A JSON object is a collection of key-value pairs enclosed in curly braces. Keys must be strings (double-quoted). Values can be any JSON data type.
{
"name": "Alice",
"age": 30,
"email": "alice@example.com"
}All JSON data types
{
"string": "Hello, world!",
"integer": 42,
"float": 3.14159,
"boolean_true": true,
"boolean_false": false,
"null_value": null,
"array": [1, 2, 3],
"object": { "key": "value" }
}JSON array
Arrays are ordered lists enclosed in square brackets:
["apple", "banana", "cherry"][1, 2, 3, 4, 5][true, false, null, 42, "mixed"]Array of objects
The most common JSON pattern in APIs — a list of records:
[
{ "id": 1, "name": "Alice", "role": "admin" },
{ "id": 2, "name": "Bob", "role": "user" },
{ "id": 3, "name": "Carol", "role": "user" }
]Nested JSON object
Objects can contain other objects and arrays at any depth:
{
"user": {
"id": 123,
"name": "Alice",
"address": {
"street": "123 Main St",
"city": "New York",
"country": "US",
"zip": "10001"
},
"tags": ["developer", "admin"]
}
}Typical REST API response
{
"status": "success",
"data": {
"id": 42,
"title": "Getting Started with JSON",
"author": {
"id": 7,
"name": "Alice Smith"
},
"tags": ["json", "tutorial", "beginner"],
"published": true,
"views": 15420,
"createdAt": "2024-01-15T10:30:00Z"
},
"meta": {
"requestId": "abc-123",
"duration": 12
}
}Paginated API response
{
"data": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
],
"pagination": {
"page": 1,
"perPage": 20,
"total": 157,
"totalPages": 8,
"hasNext": true,
"hasPrev": false
}
}Error response
{
"status": "error",
"code": 404,
"message": "User not found",
"details": {
"field": "userId",
"value": 999
}
}Configuration file (package.json style)
{
"name": "my-app",
"version": "1.0.0",
"description": "A sample application",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "jest",
"build": "webpack"
},
"dependencies": {
"express": "^4.18.2",
"lodash": "^4.17.21"
},
"devDependencies": {
"jest": "^29.0.0"
}
}GeoJSON example
GeoJSON is a standard JSON format for geographic data:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0060, 40.7128]
},
"properties": {
"name": "New York City",
"population": 8336817
}
}JSON with special string values
{
"escaped_quote": "He said \"hello\"",
"backslash": "C:\\Users\\Alice",
"newline": "Line 1\nLine 2",
"tab": "col1\tcol2",
"unicode": "\u00e9l\u00e8ve",
"emoji": "Hello \uD83D\uDE00"
}JSON rules to remember
- Keys must be double-quoted strings — not single quotes
- No trailing commas after the last item in an object or array
- No comments — JSON does not support
// or /* */comments - Numbers must not have leading zeros (except
0.5) NaNandInfinityare not valid JSON values
Validate and format your JSON
Use the JSON Formatter to validate and pretty-print your JSON, or the JSON Schema Validator to enforce a specific structure.
Frequently asked questions
What is the simplest valid JSON?
Any single JSON value is a complete valid document: "hello", 42, true, null, {}, or []. Most APIs use objects or arrays at the top level, but the spec allows any value.
What does a JSON API response typically look like?
A REST API response typically wraps data in an object with a status field, a data field (object or array), and optional meta or pagination. Error responses include status, code, and message.
How do I represent a list of users in JSON?
Use an array of user objects: [{"{"}"id": 1, "name": "Alice"{"}"}, {"{"}"id": 2, "name": "Bob"{"}"}]. For paginated APIs, wrap the array in an object with a users key and add total, page, and hasNext fields.
What is JSON for a product catalog?
An array of product objects each with id, name, price, category, inStock, and optional tags. Use a consistent price format (number + currency field) and include the same fields in every product for predictable processing.
How do I represent nested addresses in JSON?
Nest address data as an object with consistent fields: street, city, state, zip, country. For entities with multiple addresses (billing/shipping), use separate named keys for each address object.
What does an empty JSON object look like?
An empty JSON object is {} and an empty array is []. Both are valid JSON. An empty object is semantically different from null — it signals an empty collection rather than the absence of a value.
Recommended reading
- Designing Data-Intensive Applications (2nd Edition) — Martin Kleppmann & Chris RiccominiThe modern classic on data systems — encoding formats, schemas, replication, and stream processing.
- JavaScript: The Definitive Guide (7th Edition) — David FlanaganThe complete reference for the language JSON came from — serialization, async, and the full standard library.
As an Amazon Associate, Jsonic earns from qualifying purchases.