Skip to content

Field Introspection

Schema.fields() returns an array of strings with the field names in the order they were declared. This is useful for generic serialization, table headers, dynamic editing interfaces, and migration scripts — any code that needs to enumerate a schema's shape at runtime without hardcoding names.

Iterates over User.fields() with a for loop and displays the total with fields.len().

02-fields-introspection.zolo
Playground
// Feature: schema introspection — `Schema.fields()` returns field names
// Syntax: `Name.fields()` — array of strings, in declaration order.
// When to use: serialization, table headers, generic UI rendering,
// migrations — anywhere you need to enumerate the shape at runtime.

schema User {
  name: str,
  age: int,
  active: bool,
}

let fields = User.fields()
for field in fields {
  print(field)
}

// expected:
//   name
//   age
//   active

print("count: {fields.len()}")
// expected: count: 3
enespt-br