レッスン 14

List vs Object Document Patterns 日本語ガイド

日本語の json list and object patterns ガイド: Root arrays, envelope objects, pagination wrappers, and choosing a shape.

このコンテンツはまだ日本語で用意されていません。ローカライズが完了するまで English 版を表示しています。

APIs and config files choose different top-level shapes. Recognizing patterns helps you read documentation faster and design consistent endpoints.

Root array

Valid JSON can be an array at the top level:

[
  {"id": 1, "name": "Alpha"},
  {"id": 2, "name": "Beta"}
]

Common for small static lists or batch exports. Many REST APIs prefer an object wrapper instead so metadata has a home.

Envelope object

Wrap list data plus metadata:

{
  "data": [
    {"id": 1, "name": "Alpha"}
  ],
  "meta": { "total": 42, "page": 1 }
}

Names vary (data, items, results, records). The idea is the same: payload + context in one object.

Pagination fields

Repeated patterns:

{
  "items": [],
  "nextCursor": "abc123",
  "hasMore": true
}

or offset style with page, pageSize, totalCount. Clients should not assume field names—read each API’s spec.

Object-only documents

Configuration is usually a single object:

{
  "theme": "dark",
  "features": { "beta": false }
}

No array at root; nested objects group settings.

Choosing a shape

Prefer object root whenRoot array OK when
You need pagination or errors alongside dataFixed small catalog
Versioning or links objects appearInternal tools, fixtures
Multiple resource types share one endpointSimple public data feeds

Consistency within your own API matters more than copying another product’s field names.

実践したいときは関連する DevCove ツールを使えます。任意であり、このレッスンの必須部分ではありません。

関連ツールを開く

コース概要へ戻る