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

Object (SchemaDef)

The object type — structured key/value data described by a SchemaDef.

The object type validates structured key/value data. Like an array, it is a container: you declare its shape — the set of fields and their types. That shape is called a SchemaDef.

For the object value syntax ({ … }), see Objects.

Declaring the shape (SchemaDef)

addr: { street: string, city: string }   # inline SchemaDef
meta: {}                                  # any object (no fixed shape)
meta: object                              # same as {}
home: $address                            # a referenced SchemaDef

A field may itself be any type, nested object, array, or reference.

name: string, location: { x: int, y: int }
---
~ John, { 1, 2 }            # ✓ location = { x: 1, y: 2 }
~ John, { 1, two }          # ✗ invalid-type (y is not an int)

In a record with several fields, write nested objects in the open positional form (~ John, { 1, 2 }). A record written wholly as { … } maps its values to the record's fields, not to one field's object.

TypeDef

An object MemberDef accepts only the options below.

Option
Type
Description

type

string

The type name object.

default

object

Value used when the member is omitted.

schema

SchemaDef

The object's shape. Usually written inline ({ … }) instead.

optional

bool

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

null

bool

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

Nesting

Objects nest to any depth:

Open and dynamic objects

An empty SchemaDef ({} or object) accepts any object. To allow extra fields beyond those declared, add * to the shape — see Open & Dynamic Schemas:

Optional, nullable & defaults

Input
Result

valid object

the object

field fails its type

the field's error (e.g. invalid-type)

N, nullable (*)

null

N, not nullable

null-not-allowed error

omitted, optional (?)

absent

omitted, required

value-required error

Implementation status (beta)

  • Keyed null: is not yet honored — use the * suffix.

See Also

Last updated

Was this helpful?