JSON サンプル

よく使う JSON 構造の例をワンクリックでコピー

JSON とは?

JSON は軽量なデータ交換フォーマットです。JavaScript のオブジェクト表記に由来しつつ、言語に依存せず幅広い言語で扱えます。

JSON の特長:

  • 人にとって読み書きしやすい
  • 機械にとって解析・生成しやすい
  • テキストベースで言語非依存
  • Web のデータ伝送で広く利用

シンプルなオブジェクト

基本的な JSON 構造

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

ユーザープロファイル

入れ子のオブジェクトを含む情報

{
  "id": 1,
  "name": "Alice Smith",
  "email": "alice@example.com",
  "profile": {
    "avatar": "https://example.com/avatar.jpg",
    "bio": "Software Developer",
    "location": "San Francisco"
  },
  "preferences": {
    "theme": "dark",
    "notifications": true
  }
}

商品一覧

複数の製品オブジェクトを含む配列

[
  {
    "id": "p001",
    "name": "Laptop",
    "price": 999.99,
    "category": "Electronics",
    "inStock": true
  },
  {
    "id": "p002",
    "name": "Mouse",
    "price": 29.99,
    "category": "Accessories",
    "inStock": false
  }
]

API レスポンス

典型的な REST レスポンス形式

{
  "status": "success",
  "code": 200,
  "message": "Data retrieved successfully",
  "data": {
    "users": [
      {
        "id": 1,
        "name": "John",
        "role": "admin"
      },
      {
        "id": 2,
        "name": "Jane",
        "role": "user"
      }
    ],
    "pagination": {
      "page": 1,
      "limit": 10,
      "total": 25
    }
  },
  "timestamp": "2024-01-01T12:00:00Z"
}

設定ファイル

アプリ設定用の JSON

{
  "app": {
    "name": "MyApp",
    "version": "1.2.0",
    "environment": "production"
  },
  "database": {
    "host": "localhost",
    "port": 5432,
    "name": "myapp_db",
    "ssl": true
  },
  "features": {
    "authentication": true,
    "logging": true,
    "analytics": false
  }
}

入れ子配列

複数階層の複雑な構造

{
  "company": "Tech Corp",
  "departments": [
    {
      "name": "Engineering",
      "teams": [
        {
          "name": "Frontend",
          "members": [
            "Alice",
            "Bob",
            "Charlie"
          ]
        },
        {
          "name": "Backend",
          "members": [
            "David",
            "Eve",
            "Frank"
          ]
        }
      ]
    },
    {
      "name": "Marketing",
      "teams": [
        {
          "name": "Digital",
          "members": [
            "Grace",
            "Henry"
          ]
        }
      ]
    }
  ]
}

エラーレスポンス

API エラーの例

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input parameters",
    "details": [
      {
        "field": "email",
        "message": "Email format is invalid"
      },
      {
        "field": "password",
        "message": "Password must be at least 8 characters"
      }
    ]
  },
  "timestamp": "2024-01-01T12:00:00Z",
  "requestId": "req_123456789"
}

GeoJSON

地理情報データ形式

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -74.006,
          40.7128
        ]
      },
      "properties": {
        "name": "New York City",
        "population": 8336817
      }
    }
  ]
}

Package.json

Node.js プロジェクト設定ファイル

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "A sample Node.js project",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "jest",
    "build": "webpack --mode production"
  },
  "dependencies": {
    "express": "^4.18.0",
    "lodash": "^4.17.21"
  },
  "devDependencies": {
    "jest": "^29.0.0",
    "webpack": "^5.74.0"
  }
}

多様なデータ型

さまざまな JSON 型を含む例

{
  "string": "Hello World",
  "number": 42,
  "float": 3.14159,
  "boolean": true,
  "nullValue": null,
  "array": [
    1,
    "two",
    true,
    null
  ],
  "object": {
    "nested": "value"
  },
  "emptyArray": [],
  "emptyObject": {}
}

功能特性

豊富な例

代表的な 10 種の構造例

ワンクリックコピー

JSON を即座にコピー

構文ガイド

JSON の規則と型を解説

プライバシー配慮

すべてローカルで処理しデータ送信なし

よくある質問

はい。有効な JSON なのでそのままコピーして使用できます。
オブジェクト、配列、文字列、数値、真偽値、null を理解し、鍵は二重引用符で囲むことがポイントです。
JSON は厳密なデータ形式で、キーは必ず二重引用符。JS オブジェクトはより自由です。
JSON バリデータを使えば、エラー箇所を特定できます。
object / array / string / number / boolean / null の 6 種です。
仕様で定められており、言語間の互換性を担保します。