Ziggy Schema Builtin Types
any
Ziggy Schemas have one keyword for expressing that a Ziggy Document value can be of any possible type: any
All Ziggy Document values are compatible with any, but it should be considered a last-resort escape hatch. You should prefer more precise typing whenever prossible.
Basic types
Ziggy Schemas have a type name for all basic Ziggy scalar literals.
intfor an integer literalfloatfor a float literal (integer literals can be coerced)boolfortrueorfalsebytesfor a bytes literal
Note that Ziggy multiline bytes literals don’t have a corresponding type name. As far as the schema language is concerned, the two are different notations for the same type.
Language libraries will ideally offer their users ways to opt into serializing byte sequences into double quoted or multiline literals. The Zig implementation for example will default to multiline literals when a string contains newlines and no \xNN escape sequences.
Optionals
When a Ziggy value can be null, you can use the ?T notation to define an optional type, where T is a type expression.
Note that you can’t nest optionals directly. ??bytes is invalid, for example.
Examples: ?bytes, ?int
Arrays
Ziggy arrays can be defined using the []T notation, where T is a type expression.
Examples: []?bytes, ?[]bytes, [][]bool
Dictionaries
Ziggy dicts can be defined using the {:}T notation, where T is a type expression.
Examples: {:}bytes, {:}bool, {:}?[]bytes
What About Heterogeneous Arrays And Dictionaries?
Ziggy documents can indeed express heterogeneous collections:
["hi", true, 42]
{
"foo": "bar",
"bar": true,
"baz": 42,
}
But Ziggy Schema can at best represent those types as []any and {:}any. While you are certainly allowed to create Ziggy documents of this kind, in situations where you have external consumers that could benefit from a Ziggy Schema, you are kindly encouraged by the language to use structs to express type variablily.
In the Custom Types section you will also learn how to use Tagged Unions to solve some related use cases.