For the complete documentation index, see llms.txt. This page is also available as Markdown.

Array

The array type — ordered, typed collections of values.

The array type validates an ordered list of values. Unlike a scalar type, an array is a container: besides constraining the list itself (its length), you declare the type of its elements. An array with no element type accepts items of any type.

For the array value syntax ([a, b, c]), see Arrays. This page covers the array schema type.

Declaring the element type

There are two equivalent ways to declare what an array holds: the [ … ] shorthand and the keyed of: form.

tags: array                  # any array (elements unconstrained)
tags: []                     # same — any array
tags: [string]               # array of strings (shorthand)
tags: { array, of: string }  # array of strings (keyed form)

The element type may be any type, an inline object shape, or a reference:

people:  [{ name, age, role }]    # array of objects (inline shape)
authors: [$person]                # array of a referenced schema

The shorthand holds a type, not constraints. Use [ … ] for a bare element type ([string], [[int]], [{ name: string }]). To add list-level constraints such as len, switch to the keyed form: { array, of: string, len: 3 }. Writing constraints inside the brackets — { [string], len: 3 } — is not valid and raises a syntax error.

TypeDef

An array MemberDef accepts only the options below. Any other key is invalid.

Option
Type
Description

type

string

The type name array.

default

array

Value used when the member is omitted.

of

type / MemberDef

The element type. Equivalent to the [ … ] shorthand.

len

int ≥ 0

Exact number of elements required.

minLen

int ≥ 0

Minimum number of elements.

maxLen

int ≥ 0

Maximum number of elements.

optional

bool

If true, the member may be omitted. Shorthand: ? suffix on the key.

null

bool

If true, the member may be null. Shorthand: * suffix on the key.

len precedence. When len is set, minLen and maxLen are ignored.

Constraints

Element type (of)

Each element MUST satisfy the element type, or validation fails per item:

len / minLen / maxLen

default

Applies only when the member is omitted; must be a valid array.

Nested and multidimensional arrays

An element type may itself be an array, giving nested or fixed-size multidimensional arrays. Both forms below are valid:

Optional, nullable & defaults

Input
Result

value present, valid

the array

value is N (null), key is nullable (*)

null

value is N (null), key is not nullable

null-not-allowed error

value omitted, default set

the default

value omitted, key optional (?), no default

absent

value omitted, required, no default

value-required error

Implementation status (beta)

  • Keyed optional: works; keyed null: is not yet honored — use the * suffix for nullability.

  • The { [type], …constraints } combined form is not supported (use { array, of: type, … }).

Examples

Adapted from the playground (all forms below parse):

See Also

Last updated

Was this helpful?