Skip to content

zod-rs

TypeScript-first schema validation with static type inference, built for Rust

Type-safe validation

Full type safety with compile-time guarantees. Define schemas once, get validated and typed data.

Zero dependencies

Lightweight core with optional integrations for Axum and other web frameworks.

Rich error messages

Detailed validation errors with full path information, plus i18n support.

Derive macros

Automatically generate schemas from Rust structs and enums with #[derive(ZodSchema)].

TypeScript codegen

Generate TypeScript Zod schemas from Rust types with #[derive(ZodTs)].

Composable schemas

Build complex validation rules from simple primitives. Reuse schemas across your codebase.

use serde_json::json;
use zod_rs::prelude::*;
fn main() {
let schema = object()
.field("name", string().min(2).max(50))
.field("email", string().email())
.field("age", number().min(0.0).max(120.0).int());
let data = json!({
"name": "Alice",
"email": "alice@example.com",
"age": 25
});
match schema.safe_parse(&data) {
Ok(value) => println!("Valid: {:?}", value),
Err(errors) => println!("Invalid: {}", errors),
}
}