← All articles

JSON Format Examples: Objects, Arrays & Real-World Patterns

Copy-pasteable JSON examples covering every data type, nested structures, REST API responses, config files, date formats, and GeoJSON — with common error patterns and their fixes.

The best way to understand JSON is to read examples. This guide walks through the JSON format from the ground up — simple objects, nested structures, arrays, mixed types — then shows real-world JSON patterns you'll encounter in APIs, config files, and databases. Each example is valid, copy-pasteable JSON.

Use these as a sample json file for tests, fixtures, or documentation — every snippet below is a real example json value you can save with a .json extension and load directly.

The Simplest JSON Example

Any valid JSON value is a complete JSON document. The simplest possible JSON documents are primitives:

"hello"        // a string
42             // a number
true           // a boolean
null           // null

In practice, almost every JSON document you encounter is either an object or an array.

JSON Object Example

A JSON object is a collection of key–value pairs. Keys must be double-quoted strings. Values can be any JSON type.

{
  "id": 42,
  "name": "Alice Chen",
  "email": "alice@example.com",
  "age": 30,
  "active": true,
  "score": 98.6,
  "nickname": null
}

Note: key order in JSON objects is not guaranteed — parsers may return keys in any order.

JSON Array Example

A JSON array is an ordered list of values. Items can be of different types and the order is always preserved.

// Array of strings
["apple", "banana", "cherry"]

// Array of numbers
[1, 2, 3, 4, 5]

// Mixed types
[42, "hello", true, null, { "key": "value" }]

// Array of objects (common in API responses)
[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" },
  { "id": 3, "name": "Carol" }
]

Nested JSON Example

Objects and arrays can be nested to any depth. This is where JSON's expressiveness comes from.

{
  "user": {
    "id": 1001,
    "name": "Alice Chen",
    "address": {
      "street": "123 Main St",
      "city": "San Francisco",
      "state": "CA",
      "zip": "94102"
    },
    "tags": ["premium", "early-adopter"],
    "preferences": {
      "notifications": {
        "email": true,
        "sms": false,
        "push": true
      },
      "theme": "dark"
    }
  }
}

JSON Format Example: REST API Response

A typical paginated API response looks like this:

{
  "status": "success",
  "data": {
    "page": 1,
    "per_page": 10,
    "total": 47,
    "total_pages": 5,
    "items": [
      {
        "id": "prod_001",
        "name": "Wireless Headphones",
        "price": 89.99,
        "currency": "USD",
        "in_stock": true,
        "categories": ["electronics", "audio"],
        "rating": 4.7,
        "reviews_count": 2341
      },
      {
        "id": "prod_002",
        "name": "USB-C Hub",
        "price": 39.99,
        "currency": "USD",
        "in_stock": false,
        "categories": ["electronics", "accessories"],
        "rating": 4.2,
        "reviews_count": 891
      }
    ]
  },
  "meta": {
    "request_id": "req_8f3a2c",
    "timestamp": "2024-10-15T14:32:00Z"
  }
}

JSON Config File Example

Configuration files in JSON are common in JavaScript tooling. Here's a typical package.json structure:

{
  "name": "my-app",
  "version": "1.0.0",
  "description": "A sample application",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "jest",
    "build": "tsc"
  },
  "dependencies": {
    "express": "^4.18.2",
    "lodash": "^4.17.21"
  },
  "devDependencies": {
    "typescript": "^5.0.0",
    "jest": "^29.0.0"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

JSON Data Format: Date and Time

JSON has no native date type. Dates are represented as strings. ISO 8601 is the universally accepted format:

{
  "created_at": "2024-10-15T14:32:00Z",        // UTC datetime
  "updated_at": "2024-10-15T14:32:00+08:00",   // with timezone offset
  "birth_date": "1990-06-21",                   // date only
  "meeting_time": "09:00:00"                    // time only
}

Alternatively, some systems use Unix timestamps (seconds since epoch) as numbers:

{
  "created_at": 1728999120,
  "expires_at": 1761057600
}

JSON with Optional and Null Fields

Use null for fields that exist but have no value. Omit fields entirely if they are optional and absent.

{
  "id": 5,
  "name": "Bob",
  "email": "bob@example.com",
  "phone": null,            // exists but not set
  "company": "Acme Corp",
  "title": null             // exists but not set
  // "fax" is omitted entirely — not a field that applies
}

JSON Error Examples (and How to Fix Them)

These are common JSON formatting mistakes:

// ❌ Single quotes (not valid JSON)
{ 'name': 'Alice' }

// ✅ Fix: use double quotes
{ "name": "Alice" }

// ❌ Unquoted key
{ name: "Alice" }

// ✅ Fix: quote the key
{ "name": "Alice" }

// ❌ Trailing comma
{ "a": 1, "b": 2, }

// ✅ Fix: remove the trailing comma
{ "a": 1, "b": 2 }

// ❌ JavaScript comment
{ "debug": true // enable logging }

// ✅ Fix: remove the comment
{ "debug": true }

// ❌ Python boolean
{ "active": True }

// ✅ Fix: use lowercase
{ "active": true }

If you have a JSON string with any of these errors, paste it into JSON Fix to repair and format it automatically.

JSON Lines (NDJSON, jsonlines) Example

For streaming logs, ML datasets, and bulk APIs, the convention is one JSON value per line separated by \n. The format goes by two names — jsonlines (from jsonlines.org) and NDJSON — but the spec is the same:

{"event":"login","user":"ada","at":"2026-05-28T09:00:00Z"}
{"event":"view","user":"ada","page":"/dashboard"}
{"event":"logout","user":"ada","at":"2026-05-28T09:42:00Z"}

Each line parses independently. Don't JSON.parse() the whole file — split on the newline and parse line by line.

OpenAPI Response Example

An OpenAPI spec defines responses using a JSON Schema-flavoured shape:

{
  "openapi": "3.1.0",
  "paths": {
    "/users/{id}": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["id", "email"],
                  "properties": {
                    "id":    { "type": "integer" },
                    "email": { "type": "string", "format": "email" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Date-Only and Time-Only Examples

ISO 8601 also defines pure date and pure time forms — useful when the time-of-day or the date is genuinely not meaningful:

{
  "birth_date":   "1815-12-10",         // date only
  "office_hours": "09:00:00",           // time only
  "started_at":   "2026-05-28T09:00:00Z" // full datetime, for contrast
}

GeoJSON Example

GeoJSON is a standard format for geographic data based on JSON:

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [-122.4194, 37.7749]
  },
  "properties": {
    "name": "San Francisco",
    "country": "US",
    "population": 873965
  }
}

Frequently Asked Questions

What is an example of valid JSON?

The simplest is a single primitive like 42 or "hello", but most real JSON is an object such as { "name": "Alice", "age": 30, "active": true } or an array of such objects.

How are dates represented in JSON?

JSON has no date type. Dates are stored as strings — ISO 8601 ("2024-10-15T14:32:00Z") is the universal choice — or as numeric Unix timestamps.

How do I represent a missing value in JSON?

Use null for a field that exists but has no value, and omit the key entirely for fields that don't apply. JSON has no undefined.

What does nested JSON look like?

Objects and arrays can contain other objects and arrays to any depth — see the nested and REST-API examples above. For the underlying rules, see What Is JSON?

Try These Examples

Copy any of the examples above and paste them into the tools below to explore the data:

  • JSON Fix — format, validate, and repair JSON
  • JSON Diff — compare two JSON examples side by side
  • What Is JSON? — a complete guide to the six data types and the JSON grammar
  • How to Format JSON — pretty-print JSON in JavaScript, Python, jq, and your browser
  • JSON Stringify — convert a JSON value to an escaped string literal