JSON Schema - for Zig (scaffold)
This project explores a Zig-native approach to JSON Schema by building on two
core ideas:
Zigstruct generation fromJSON SchemaRuntime.- validation of
JSONpayloads against those generatedZigstructures.
The long-term goal is to express JSON Schema semantics directly through Zig’s
type system and tooling.
Disclamer
This project is currently a scaffold.
Parsing and code generation are intentionally simplistic at this stage.
The focus so far has been on establishing a correct and idiomatic Zig pipeline
rather than full schema coverage.
Current state
Before expanding functionality, the following end-to-end pipeline has been
implemented without external tools:
- Build and run a generator that takes input and output files
- Parse a minimal
JSONSchema representation - Generate a corresponding
Zigstruct - Delegate all formatting to
Zig’s own formatter (std.zig.Ast)
This ensures that future work can focus purely on semantics and correctness
rather than tooling friction.
Try it out
Run from repo root:
$ zig build run -- src/resources/simple_schema.json src/resources/simple_schema.zig
$ cat src/resources/simple_schema.zig
Output:
pub const Schema = struct {
name: []const u8,
age: u8,
};
You can replay it with the generated executable:
$ zig-out/bin/json_schema src/resources/simple_schema.json src/resources/simple_schema.zig
It can be found here: