Schemas are types
Composition is checked by the compiler; invalid schema combinations fail the build.
Compile-time schema composition, explicit allocation, structured errors.
const std = @import("std");
const z = @import("zigantic");
const User = struct { name: []const u8, email: []const u8, age: u8 };
const UserSchema = z.object(User, .{
.name = z.string(.{ .min = 1, .trim = true }),
.email = z.email(.{}),
.age = z.integer(u8, .{ .min = 18 }),
}, .{});
pub fn main() !void {
var result = try z.parse(UserSchema, std.heap.page_allocator,
\{"name":"Ada","email":"ada@example.com","age":36}
, .{});
defer result.deinit();
if (result.value) |user| {
std.debug.print("{s} <{s}>\n", .{ user.name, user.email });
}
}Install with the release tarball or nightly Git URL; see installation.