← All articles

JSON Format Examples: Valid Objects, Arrays, API Responses, Config Files, and Edge Cases

Copy valid JSON examples for objects, arrays, API responses, config files, dates, nulls, escaped strings, JSON Lines, OpenAPI, GeoJSON, and common syntax mistakes.

JSON examples are only useful when they are actually valid JSON. A surprising number of "JSON examples" online include comments, trailing commas, JavaScript values, or several top-level values in one snippet. Those are useful for explaining mistakes, but they are not copy-pasteable JSON.

This page keeps the line clean: code blocks marked json are valid JSON documents you can paste into JSON Validator, save as .json files, or use as test fixtures. When an example is intentionally broken, it is marked as invalid.

Quick Valid JSON Examples

A JSON document can be any one JSON value. In real files and API responses, the top-level value is usually an object or an array.

Object:

{
  "id": 42,
  "name": "Alice Chen",
  "active": true
}

Array:

[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" }
]

String:

"hello"

Number:

42

Boolean:

true

Null:

null

Those six value types are the entire JSON data model: object, array, string, number, boolean, and null. There is no date type, integer type, comment type, undefined, NaN, or Infinity.

What Makes These Examples Valid JSON?

Use this checklist before copying a JSON example into a test, API request, or config file.

Rule Valid Invalid
Keys use double quotes { "name": "Ada" } { name: "Ada" }
Strings use double quotes { "name": "Ada" } { "name": 'Ada' }
No trailing commas { "a": 1, "b": 2 } { "a": 1, "b": 2, }
No comments { "debug": true } { "debug": true // local }
Lowercase literals { "active": true, "deleted": null } { "active": True, "deleted": None }
One top-level value { "ok": true } { "a": 1 } { "b": 2 }

Whitespace is allowed between tokens. Indentation does not change the data. The minified and pretty versions below represent the same object:

{"id":42,"name":"Alice","active":true}
{
  "id": 42,
  "name": "Alice",
  "active": true
}

JSON Object Example

A JSON object is a set of name/value pairs wrapped in {}. Object keys must be strings, and string keys must use double quotes.

{
  "id": "usr_1001",
  "name": "Alice Chen",
  "email": "alice@example.com",
  "role": "admin",
  "active": true,
  "login_count": 184,
  "last_login_at": "2026-05-19T14:32:00Z",
  "phone": null
}

A few practical details matter:

  • id is a string here because many production IDs contain prefixes or can exceed JavaScript's safe integer range.
  • phone is present with null, which means "known field, no value."
  • Object key order is not a reliable contract. If you need stable diffs, format with sorted keys in a formatter or with jq -S.
  • Avoid duplicate keys. Many parsers accept them, but the last value usually wins after parsing.

JSON Array Example

A JSON array is an ordered list wrapped in []. Arrays often hold objects of the same shape.

[
  {
    "id": "ord_1001",
    "status": "paid",
    "total": 42.5
  },
  {
    "id": "ord_1002",
    "status": "failed",
    "total": 0
  },
  {
    "id": "ord_1003",
    "status": "paid",
    "total": 118
  }
]

Mixed arrays are valid, but they are harder to validate and consume:

[
  "ready",
  42,
  true,
  null,
  { "source": "api" }
]

Use mixed arrays only when the consumer expects mixed types. For API responses, arrays of similarly shaped objects are easier to document, validate, and query.

Nested JSON Example

Nested JSON uses objects inside objects, arrays inside objects, and objects inside arrays.

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

Keep nesting purposeful. Deeply nested JSON is valid, but every extra level makes queries, validation errors, and partial updates harder to read.

REST API Response Example

A common API response wraps the actual records in data and keeps pagination or request details in separate metadata fields.

{
  "status": "success",
  "data": {
    "items": [
      {
        "id": "prod_001",
        "name": "Wireless Headphones",
        "price_cents": 8999,
        "currency": "USD",
        "in_stock": true,
        "categories": ["electronics", "audio"]
      },
      {
        "id": "prod_002",
        "name": "USB-C Hub",
        "price_cents": 3999,
        "currency": "USD",
        "in_stock": false,
        "categories": ["electronics", "accessories"]
      }
    ],
    "pagination": {
      "page": 1,
      "per_page": 10,
      "total_items": 47,
      "total_pages": 5
    }
  },
  "meta": {
    "request_id": "req_8f3a2c",
    "generated_at": "2026-05-19T14:32:00Z"
  }
}

Notice the money field. price_cents is an integer number of cents, not a floating-point dollar amount. That avoids rounding surprises in languages where decimal money does not fit cleanly into a binary floating-point number.

JSON Config File Example

Strict JSON config files cannot contain comments. This package.json-style example is valid as written:

{
  "name": "json-example-app",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 0.0.0.0",
    "test": "vitest run",
    "build": "tsc && vite build"
  },
  "dependencies": {
    "zod": "^3.25.0"
  },
  "devDependencies": {
    "typescript": "^5.8.0",
    "vitest": "^3.2.0"
  },
  "engines": {
    "node": ">=20.0.0"
  }
}

Some tools use JSON-like formats with comments, especially tsconfig.json and VS Code settings.json. That dialect is often called JSONC. It is convenient for humans, but it is not strict JSON. A normal JSON.parse() call will reject comments and trailing commas.

Dates and Times in JSON

JSON has no date type. Dates and times are usually strings.

{
  "created_at": "2026-05-19T14:32:00Z",
  "updated_at": "2026-05-19T15:04:12-07:00",
  "birth_date": "1990-06-21",
  "office_opens_at": "09:00:00"
}

Use an ISO 8601 date-time string with a timezone (Z or an offset) when the value represents a moment in time. Use a date-only string for birthdays, billing cycles, holidays, or other values where a timezone would be misleading.

Some systems use Unix timestamps:

{
  "created_at": 1779201120,
  "expires_at": 1781793120
}

If you choose timestamps, document whether they are seconds or milliseconds. Mixing the two is one of the fastest ways to create dates that are off by a factor of 1000.

Numbers, IDs, and Money

JSON has one number type. It does not distinguish integers, floats, decimals, or big integers.

Use numbers for ordinary counts and measurements:

{
  "quantity": 4,
  "rating": 4.7,
  "weight_kg": 1.25
}

Use strings for identifiers that are not meant for arithmetic:

{
  "user_id": "9223372036854775807",
  "invoice_id": "inv_2026_000184",
  "postal_code": "94102"
}

Use integer minor units or decimal strings for money:

{
  "total_cents": 11800,
  "currency": "USD",
  "tax_rate": "0.0875"
}

This is a data-contract decision, not only a formatting decision. Pick one representation and keep it consistent across API requests, responses, tests, and documentation.

Null, Missing Fields, and Empty Collections

Use null when a field exists but has no value. Omit the key when the field does not apply. Use an empty array or object when the collection exists but contains nothing.

{
  "id": "usr_1002",
  "name": "Bob Lee",
  "email": "bob@example.com",
  "phone": null,
  "company": null,
  "roles": [],
  "settings": {}
}

If the consumer needs to tell "unknown" apart from "not applicable," make that explicit in your schema or API docs. Do not rely on readers guessing the difference between null, missing, "", and [].

Escaped String Examples

JSON strings use double quotes, so quotes and backslashes inside the value need escaping.

{
  "quote": "She said \"hello\" and left.",
  "windows_path": "C:\\Users\\Alice\\Downloads",
  "message": "line one\nline two",
  "tabbed": "name\tvalue"
}

The message value contains the escaped sequence \n, not a raw line break inside the JSON string. Raw control characters inside strings produce errors like Bad Control Character in JSON.

JSON Stored Inside a JSON String

Sometimes a field contains serialized JSON as a string. This happens in message queues, webhook envelopes, legacy database columns, and logs.

{
  "id": "evt_91",
  "type": "webhook.received",
  "payload": "{\"order_id\":\"ord_1001\",\"status\":\"paid\"}"
}

Here payload is a string, not an object. In JavaScript, parse the outer document first and then parse the inner field:

const outer = JSON.parse(raw);
const payload = JSON.parse(outer.payload);

When creating this format, do not escape the inner quotes by hand. Build the inner object, stringify it, and then stringify the outer object:

const payload = JSON.stringify({ order_id: 'ord_1001', status: 'paid' });
const json = JSON.stringify({ id: 'evt_91', type: 'webhook.received', payload });

JSON Lines and NDJSON Example

JSON Lines, also called NDJSON, is not one JSON document. It is one valid JSON value per line.

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

Do not parse the whole file with one JSON.parse() call. Parse each non-empty line:

const events = text
  .split('\n')
  .filter(Boolean)
  .map((line) => JSON.parse(line));

Use JSON Lines for streaming logs, bulk imports, and machine-learning datasets where appending one record at a time matters.

OpenAPI Response Schema Example

OpenAPI 3.1 uses JSON Schema vocabulary to describe API payloads. The spec itself can be written as JSON.

{
  "openapi": "3.1.0",
  "info": {
    "title": "Users API",
    "version": "1.0.0"
  },
  "paths": {
    "/users/{id}": {
      "get": {
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "User found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["id", "email"],
                  "properties": {
                    "id": { "type": "string" },
                    "email": { "type": "string", "format": "email" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

The example is valid JSON, but it is also a contract. A JSON validator checks syntax; a schema validator checks whether a response matches the contract.

GeoJSON Example

GeoJSON is JSON with a specific geographic structure.

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

For a point, coordinates are [longitude, latitude], not [latitude, longitude]. That order is a classic GeoJSON mistake because map UIs often display the values the other way around.

Invalid JSON Examples and Fixes

The following examples are intentionally invalid.

Single quotes:

{ 'name': 'Alice' }

Fix:

{ "name": "Alice" }

Unquoted key:

{ name: "Alice" }

Fix:

{ "name": "Alice" }

Trailing comma:

{ "a": 1, "b": 2, }

Fix:

{ "a": 1, "b": 2 }

Comment:

{ "debug": true // enable logging }

Fix:

{ "debug": true }

Python values:

{ "active": True, "deleted": None }

Fix:

{ "active": true, "deleted": null }

JavaScript-only values:

{ "value": undefined, "score": NaN }

Fix:

{ "value": null, "score": null }

Raw newline inside a string:

{ "message": "line one
line two" }

Fix:

{ "message": "line one\nline two" }

If you have almost-JSON with these mistakes, paste it into JSON Fix to repair and format it locally. If you only need a strict yes/no check, use JSON Validator.

Validate These Examples Yourself

In JavaScript:

const value = JSON.parse(text);
console.log(value);

On the command line with jq:

jq empty example.json

With Python:

python3 -m json.tool example.json > /dev/null

For formatting options, see How to Format JSON. For schema rules such as required fields and types, see What Is JSON Schema?.

Frequently Asked Questions

What is an example of valid JSON?

A simple valid JSON object is { "name": "Alice", "age": 30, "active": true }. A JSON document can also be an array, string, number, boolean, or null, but most API responses and .json files use an object or array.

Can a JSON file start with an array?

Yes. A .json file can contain any single JSON value, including an array. Many APIs return arrays directly, although object wrappers with data and meta are easier to extend later.

Are comments allowed in JSON examples?

No. Comments are not valid JSON. If a code block contains // or /* */, it is JSONC, JavaScript, or an intentionally invalid example, not strict JSON.

How should dates be represented in JSON?

Use strings, usually ISO 8601 date-time strings such as "2026-05-19T14:32:00Z". JSON has no native date type. Unix timestamps are also common, but you must document seconds vs milliseconds.

Should JSON IDs and money values be strings or numbers?

Use strings for IDs that are not meant for arithmetic, especially large IDs, prefixed IDs, ZIP codes, and account numbers. For money, use integer minor units such as cents or a documented decimal string.

How do I represent a missing value in JSON?

Use null when the field exists but has no value. Omit the key when the field does not apply. Use [] or {} when an empty collection is the actual value.

What is the difference between JSON and JSON Lines?

JSON is one complete value. JSON Lines or NDJSON is one JSON value per line, commonly used for logs and bulk data. Parse JSON Lines line by line, not with one JSON.parse() call over the whole file.

How do I check that a JSON example is valid?

Paste it into JSON Validator, run jq empty example.json, or parse it with JSON.parse() or Python's json module. Syntax validation only proves the JSON parses; use JSON Schema for required fields and types.

Try These Examples

Copy any valid JSON example above and paste it into these tools:

Sources

Last reviewed July 2026.