liveBook · Manning

Array

As explained in The Design of Web APIs, Second Edition

An array is an ordered collection of values in a serialized data format.

An array is an ordered collection of values, commonly represented in JSON with brackets and comma-separated elements. JSON arrays can contain strings, numbers, Booleans, objects, arrays, or null values. section 5.1.2

Arrays are useful for representing collections such as a catalog of products or a product’s keywords. A collection resource may be modeled as an array, while an individual resource is modeled as an object. section 5.2.1 section 5.2.3

Design arrays with consumer usability and future change in mind:

  • Describe an array property in JSON Schema with type: array and an items schema defining each element. section 7.4.5
  • Use arrays to group similar data, making related business concepts easier to browse and understand. section 8.6.2
  • Keep small, essential lists embedded; separate large lists that need filtering or pagination into dedicated resource models and operations. section 8.7.2
  • Prefer arrays of objects when elements may later need additional data; arrays of atomic values are suitable when each value is self-sufficient. section 15.6.3
  • Use an object at request and response body level when future metadata or extension may be required, because a bare array cannot be extended without changing the contract. section 15.6.3 section 5.2.1

Product keywords

A Product schema can define keywords as an array of strings: keywords: { type: array, items: { type: string } }. The same items position can contain an object schema when each element needs structured fields. section 7.4.5

Listing 7.7 An array of strings
...
Product:
  type: object
  properties:
    ...
    keywords:
      type: array    #1
      items:     #2
        type: string    #3

Inspect the compact OpenAPI schema for an array of strings and its items definition. section 7.4.5

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains JSON representation, resource modeling, schema syntax, embedding trade-offs, and extensibility, while deferring array-size constraints.
Examples
Uses catalogs, product keywords, bank-account balances, transactions, owners, tags, and grouped transfer events.
What it assumes
Assumes basic API data modeling and portable types while teaching array representation and schema definition directly.
What you can do after
Build it from scratch by modeling collections, defining items schemas, and choosing between embedded, object-based, and separate lists.
How it connects
Connects arrays with JSON, YAML, JSON Schema, OpenAPI, resource models, pagination, filtering, and extensible design.

Also explained in

Compare how 40 books explain array →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.