Skip to content

ziganticValidation and schemas for Zig

Compile-time schema composition, explicit allocation, structured errors.

Quick example ​

zig
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.

Explore ​

  • Quick start builds and runs the first schema.
  • Examples walks through nine complete programs, each with its output.
  • API reference documents every constructor, config struct and option.

Released under the MIT License.