レッスン 3

Arrays, Enums, and Formats 日本語ガイド

日本語の json schema arrays enums and formats ガイド: Describe lists, allowed values, dates, email addresses, URLs, and UUIDs.

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

Objects describe named fields. Arrays, enums, and formats describe the common constraints that appear inside those fields.

Arrays

Use items to describe each element in an array:

{
  "type": "array",
  "items": { "type": "string" }
}

For an array of objects, place an object schema inside items:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "sku": { "type": "string" },
      "quantity": { "type": "integer", "minimum": 1 }
    },
    "required": ["sku", "quantity"]
  }
}

Enums

enum limits a value to a known set:

{
  "type": "string",
  "enum": ["draft", "published", "archived"]
}

Enums are useful for workflow states, modes, roles, and controlled labels. Avoid using enums for values that change frequently outside code, such as customer names.

Formats

format annotates strings with semantic intent:

  • email
  • uri
  • uuid
  • date
  • date-time

Validators differ in how strictly they enforce formats. In many libraries, format validation requires an extra package or option. Treat format as helpful validation, not a replacement for domain-specific checks.

Generated schemas need review

Schema generators can infer useful defaults from examples, but a sample only shows what happened once. Review arrays, enums, and formats before publishing the schema as a contract.

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

関連ツールを開く

コース概要へ戻る