Lección 14

List vs Object Document Patterns en español

Guía en español para json list and object patterns: Root arrays, envelope objects, pagination wrappers, and choosing a shape.

Este contenido todavía no está disponible en español. Se muestra la versión en English mientras completamos la localización.

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.

Volver al resumen del curso