Lesson 3

Arrays, Enums, and Formats

Describe lists, allowed values, dates, email addresses, URLs, and UUIDs.

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.

When you want to practice, use the related DevCove tool — optional, not part of this lesson.

Open related tool

Back to course overview