JSON Examples

JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. These examples cover every JSON data type and common real-world patterns, from simple strings to complex nested API responses.

Simple 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)
  • NaN and Infinity are 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.