Introduction ​
zigantic validates wire data and decodes it into ordinary Zig values. A schema is a type: z.string(.{}), z.integer(u8, .{}) and z.object(Model, .{...}, .{}) each return a type with a Value declaration and a common operation set:
decode: astd.json.Valuetree toValue;check: validate an already-typedValue;encode: write aValuethrough the standard JSON writer;writeJsonSchema: emit a JSON Schema description;decodeString: decode one textual component for query and form input, where the schema has a text representation.
Composition is resolved by the compiler. Invalid field types, unknown fields, mismatched union variants and incompatible intersections fail the build. There is no runtime schema interpreter.
Zig 0.17 standard-library reuse ​
The implementation targets Zig 0.17 and reuses the current standard library instead of maintaining parallel parsers, writers, URI logic or calendar code:
std.jsonparses input intostd.json.Valueandstd.json.Stringifywrites output throughstd.Io.Writer;std.Uriandstd.SemanticVersionback URL and semantic-version checks;std.asciisupplies character classification and case conversion;std.mathsupplies integer bounds, finite checks and ordering;std.array_hash_map.Stringis the record value type;std.Io.Clock.Timestampis used by the benchmark harness.
Zig 0.17 syntax is used throughout, including @typeInfo(...).@"struct", @typeName, @Struct, @Tuple, std.Io.Writer and std.mem.Allocator. Only the Zig 0.17 package in the repository CI is supported.
Declared and inferred models ​
A schema can bind to a model you declare:
const User = struct {
name: []const u8,
age: u8,
};
const UserSchema = z.object(User, .{
.name = z.string(.{ .min = 1 }),
.age = z.integer(u8, .{ .min = 18 }),
}, .{});Zig 0.17 can also construct types. z.objectOf synthesizes a struct with @Struct, z.tuple synthesizes a tuple with @Tuple, and z.intersection checks several schemas against one value:
const Profile = z.objectOf(.{
.name = z.string(.{ .min = 1 }),
.age = z.integer(u8, .{ .min = 18 }),
}, .{});
const Point = z.tuple(.{
.x = z.float(f64, .{}),
.y = z.float(f64, .{}),
}, .{});See Inferred Objects, Tuples & Intersections for the full rules and examples.
Complete schema surface ​
- Objects:
z.objectfor declared models andz.objectOffor inferred ones, with naming policies, aliases, unknown-field policy and defaults;z.merge,z.extend,z.pickandz.omitcompose inferred field sets. - Collections:
z.array,z.fixedArray,z.set,z.recordandz.tuple. - Products and sums:
z.tuple,z.intersection,z.unionOfandz.discriminatedUnion. - Primitives: strings and formats, integers, floats, booleans, enums, literals, null,
z.bytesand temporal schemas. - Modifiers:
optional,nullable,nullish,withDefault,withDefaultFactory,fallback,refine,meta,transform,codec,lazyandcustom. - Wire services:
z.parse,z.stringify,z.parseQuery,z.parseForm,z.stringifyQuery,z.validate,z.checkFirstandz.jsonSchema. - Date and time:
z.Date,z.Timeandz.DateTimefor calendar arithmetic after the ISO 8601 string schemas validate the wire text.
Ownership ​
Validation predicates allocate nothing. Decoding allocates from a per-result arena owned by the caller's allocator; ParseResult.deinit frees everything. z.checkFirst validates typed values with caller scratch memory and no heap allocation. z.stringify creates one scratch arena for transform encoders and releases it before returning the caller-owned buffer.
Borrowed input slices stay valid only while the source document lives. Decoded strings, collections and records are owned by the result arena; issue paths and messages are owned by the issue list. The library never opens files, reads environment variables or keeps global configuration. Every service takes a trailing options value, and every allocation is visible in its signature. See Ownership & Allocators for the full allocation matrix and failure-path rules.
Composition and wire boundaries ​
Schemas nest freely inside objects, arrays, records, tuples and unions. Modifiers distinguish absent keys from explicit null, make mappings reversible with .encode, and support recursive models with z.lazy. Recursive JSON Schema output uses $defs and $ref instead of a permissive placeholder.
Some values deliberately have no external representation. A z.custom value is check-only: decode reports E021 and encode and JSON Schema return error.Unsupported. A transform without .encode is likewise not serializable. Query serialization traverses objects, records, tuples, arrays, intersections, lazy nodes and scalar leaves; unions, transforms without a query form and custom values return error.Unsupported instead of emitting incomplete text.
Known limitations ​
- JSON Schema output targets Draft 2020-12, Draft 2019-09, Draft 7, Draft 6 and Draft 5. OpenAPI 3.0 output and JSON Schema import are not implemented.
multipart/form-dataparsing is not implemented; URL-encoded forms are.- Pattern validation uses the built-in formats and string predicates. A general regular-expression engine is not bundled to keep the package dependency-free.
- Objects reject or strip unknown keys. Preserving unknown keys would need an explicit model field and is not automatic.
- Tuples have fixed arity; variadic tuples are not implemented.
- Records use string keys. Maps with arbitrary key types are not implemented.
- String lengths and format checks operate on bytes and ASCII, not grapheme clusters or full Unicode normalization.
What it is not ​
- Not an ORM or a database layer.
- Not a replacement for
std.json; it builds on it. - Not a runtime schema interpreter; schemas and their checks exist at compile time, and decoded values are ordinary Zig values.
