JSON Examples - Complete Guide with Real-World Samples

Learn JSON with copy-paste ready examples from simple to complex

Published: January 2025 • 10 min read

JSON (JavaScript Object Notation) is a lightweight data format used everywhere in modern web development. Whether you're working with REST APIs, configuration files, or data exchange, understanding JSON is essential.

This guide provides practical, copy-paste ready JSON examples from simple to complex. All examples are valid JSON that you can test in our JSON Formatter or JSON Validator.

Quick Tip: JSON uses key-value pairs, supports strings, numbers, booleans, null, arrays, and objects. Learn more about JSON syntax basics.

Simple JSON Object Example

A basic JSON object contains key-value pairs enclosed in curly braces {}. Keys must be strings (in double quotes), and values can be strings, numbers, booleans, or null.

Example: Person Object

{
  "name": "John Doe",
  "age": 30,
  "city": "New York",
  "isEmployed": true
}

Keys: "name", "age", "city", "isEmployed"
Values: string, number, string, boolean

JSON Data Types Examples

JSON supports six data types. Here's an example showing all of them:

All Data Types in One Object

{
  "string": "Hello World",
  "number": 42,
  "float": 3.14,
  "boolean": true,
  "nullValue": null,
  "array": [1, 2, 3],
  "object": {
    "key": "value"
  }
}
String: Text in double quotes
Number: Integer or floating-point
Boolean: true or false
Null: Represents empty value
Array: Ordered list in square brackets
Object: Nested key-value pairs

JSON Array Examples

Arrays in JSON are ordered lists enclosed in square brackets []. They can contain any JSON data type.

Simple Array

{
  "fruits": ["apple", "banana", "orange"],
  "numbers": [1, 2, 3, 4, 5],
  "mixed": ["text", 42, true, null]
}

Array of Objects

{
  "users": [
    {
      "id": 1,
      "name": "Alice",
      "email": "[email protected]"
    },
    {
      "id": 2,
      "name": "Bob",
      "email": "[email protected]"
    },
    {
      "id": 3,
      "name": "Charlie",
      "email": "[email protected]"
    }
  ]
}

Common pattern for API responses returning multiple items.

Nested JSON Object Examples

JSON objects can contain other objects, creating nested structures. This is common in real-world applications.

User Profile with Nested Objects

{
  "user": {
    "id": 12345,
    "username": "johndoe",
    "profile": {
      "firstName": "John",
      "lastName": "Doe",
      "age": 28,
      "address": {
        "street": "123 Main St",
        "city": "San Francisco",
        "state": "CA",
        "zipCode": "94102",
        "country": "USA"
      }
    },
    "preferences": {
      "theme": "dark",
      "notifications": true,
      "language": "en"
    }
  }
}

Multiple levels of nesting: user → profile → address

Real-World JSON Examples

Example 1: REST API Response

{
  "status": "success",
  "data": {
    "user": {
      "id": 101,
      "name": "Sarah Johnson",
      "email": "[email protected]",
      "avatar": "https://example.com/avatars/sarah.jpg",
      "createdAt": "2024-01-15T10:30:00Z"
    }
  },
  "message": "User retrieved successfully",
  "timestamp": 1705315800
}

Typical structure for REST API responses with status, data, and metadata.

Example 2: Configuration File

{
  "appName": "MyAwesomeApp",
  "version": "2.1.0",
  "environment": "production",
  "server": {
    "host": "api.example.com",
    "port": 443,
    "protocol": "https"
  },
  "database": {
    "type": "postgresql",
    "host": "db.example.com",
    "port": 5432,
    "name": "myapp_db",
    "ssl": true
  },
  "features": {
    "enableCache": true,
    "maxRetries": 3,
    "timeout": 5000
  }
}

Common pattern for application configuration files.

Example 3: E-commerce Product

{
  "product": {
    "id": "PROD-12345",
    "name": "Wireless Bluetooth Headphones",
    "brand": "AudioTech",
    "price": {
      "amount": 79.99,
      "currency": "USD",
      "discount": 10
    },
    "availability": {
      "inStock": true,
      "quantity": 247
    },
    "specifications": {
      "color": "Black",
      "weight": "250g",
      "batteryLife": "30 hours",
      "bluetooth": "5.0"
    },
    "images": [
      "https://example.com/images/headphones-1.jpg",
      "https://example.com/images/headphones-2.jpg",
      "https://example.com/images/headphones-3.jpg"
    ],
    "ratings": {
      "average": 4.5,
      "count": 1024
    },
    "categories": ["Electronics", "Audio", "Headphones"]
  }
}

Typical product data structure for e-commerce platforms.

Example 4: Weather API Response

{
  "location": {
    "city": "London",
    "country": "UK",
    "coordinates": {
      "latitude": 51.5074,
      "longitude": -0.1278
    }
  },
  "current": {
    "temperature": 18,
    "feelsLike": 16,
    "humidity": 65,
    "condition": "Partly Cloudy",
    "windSpeed": 15,
    "visibility": 10
  },
  "forecast": [
    {
      "day": "Monday",
      "high": 20,
      "low": 14,
      "condition": "Sunny"
    },
    {
      "day": "Tuesday",
      "high": 19,
      "low": 13,
      "condition": "Rainy"
    }
  ],
  "lastUpdated": "2025-01-16T14:30:00Z"
}

Weather data structure similar to OpenWeatherMap API.

Example 5: package.json (Node.js)

{
  "name": "my-awesome-project",
  "version": "1.0.0",
  "description": "An awesome Node.js project",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "jest",
    "build": "webpack --mode production"
  },
  "keywords": ["node", "javascript", "api"],
  "author": "John Doe <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "express": "^4.18.2",
    "mongoose": "^7.0.3"
  },
  "devDependencies": {
    "jest": "^29.5.0",
    "webpack": "^5.82.0"
  }
}

Standard package.json structure for Node.js projects.

Example 6: Restaurant Menu

{
  "restaurant": {
    "name": "The Golden Plate",
    "address": "123 Food Street, NYC",
    "menu": {
      "appetizers": [
        {
          "id": "APP-001",
          "name": "Caesar Salad",
          "description": "Fresh romaine lettuce with parmesan",
          "price": 8.99,
          "vegetarian": true,
          "calories": 320
        },
        {
          "id": "APP-002",
          "name": "Buffalo Wings",
          "description": "Spicy chicken wings with blue cheese",
          "price": 12.99,
          "vegetarian": false,
          "calories": 580
        }
      ],
      "mainCourse": [
        {
          "id": "MAIN-001",
          "name": "Grilled Salmon",
          "description": "Atlantic salmon with herbs",
          "price": 24.99,
          "vegetarian": false,
          "glutenFree": true,
          "calories": 450
        }
      ],
      "desserts": [
        {
          "id": "DES-001",
          "name": "Chocolate Cake",
          "description": "Rich chocolate layer cake",
          "price": 7.99,
          "vegetarian": true,
          "calories": 420
        }
      ]
    }
  }
}

Menu structure with categories, items, and dietary information.

Complex Nested JSON Example

Here's a more complex example showing deep nesting, arrays of objects, and multiple data types:

Company Organization Structure

{
  "company": {
    "name": "TechCorp Inc",
    "founded": 2010,
    "headquarters": {
      "city": "San Francisco",
      "state": "CA",
      "country": "USA"
    },
    "departments": [
      {
        "id": "ENG",
        "name": "Engineering",
        "budget": 5000000,
        "employees": [
          {
            "id": 101,
            "name": "Alice Smith",
            "role": "Senior Engineer",
            "salary": 150000,
            "skills": ["Python", "JavaScript", "AWS"],
            "projects": [
              {
                "name": "Project Alpha",
                "status": "active",
                "completion": 75
              }
            ]
          },
          {
            "id": 102,
            "name": "Bob Johnson",
            "role": "Tech Lead",
            "salary": 180000,
            "skills": ["Go", "Kubernetes", "Docker"],
            "projects": [
              {
                "name": "Project Beta",
                "status": "completed",
                "completion": 100
              },
              {
                "name": "Project Gamma",
                "status": "planning",
                "completion": 10
              }
            ]
          }
        ]
      },
      {
        "id": "MKT",
        "name": "Marketing",
        "budget": 2000000,
        "employees": [
          {
            "id": 201,
            "name": "Carol White",
            "role": "Marketing Manager",
            "salary": 120000,
            "skills": ["SEO", "Content Strategy", "Analytics"],
            "campaigns": [
              {
                "name": "Summer Launch",
                "status": "active",
                "budget": 50000
              }
            ]
          }
        ]
      }
    ],
    "financials": {
      "revenue": 50000000,
      "expenses": 35000000,
      "profit": 15000000,
      "year": 2024
    }
  }
}

This example shows multiple levels of nesting with arrays of objects containing more nested objects and arrays.

Common JSON Patterns

Pagination Response

{
  "data": [
    {"id": 1, "name": "Item 1"},
    {"id": 2, "name": "Item 2"},
    {"id": 3, "name": "Item 3"}
  ],
  "pagination": {
    "page": 1,
    "pageSize": 20,
    "totalPages": 5,
    "totalItems": 100,
    "hasNext": true,
    "hasPrevious": false
  }
}

Error Response

{
  "status": "error",
  "error": {
    "code": 404,
    "message": "Resource not found",
    "details": "User with ID 12345 does not exist"
  },
  "timestamp": "2025-01-16T14:30:00Z",
  "path": "/api/users/12345"
}

Authentication Token Response

{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "dGVzdC1yZWZyZXNoLXRva2VuLWV4YW1wbGU...",
  "tokenType": "Bearer",
  "expiresIn": 3600,
  "user": {
    "id": 12345,
    "username": "johndoe",
    "email": "[email protected]"
  }
}

JSON Syntax Rules

1.
Keys must be strings: Always use double quotes for keys: "name" not name
2.
Use double quotes: Single quotes are not valid: "text" not 'text'
3.
No trailing commas: Last item shouldn't have a comma after it
4.
No comments: JSON doesn't support comments. See our Comments in JSON guide
5.
Case sensitive: true is valid, True is not
6.
Data types: Only string, number, boolean, null, array, and object are supported

Test These Examples

Want to try these examples? Use our free online tools:

Learn More About JSON

Summary

JSON is a simple yet powerful data format used throughout modern web development. The examples in this guide cover:

  • Basic JSON objects and data types
  • JSON arrays and nested structures
  • Real-world examples from APIs and configuration files
  • Common patterns like pagination and error responses
  • JSON syntax rules and best practices

Next Steps: Try our JSON Formatter to format your own JSON, or learn about parsing JSON in Python.