vld-ts
Generate TypeScript Zod schemas from JSON Schema definitions produced by vld.
Overview
vld-ts takes standard JSON Schema objects (as serde_json::Value) and converts them into TypeScript Zod schema code strings. This enables sharing a single validation contract between your Rust backend and TypeScript frontend.
Installation
[]
= "0.1"
= "1"
Quick start
use ;
// Single schema
let schema = json!;
let zod = json_schema_to_zod;
// => z.object({ name: z.string().min(2).max(50), email: z.string().email(), ... })
// Generate a complete .ts file with multiple schemas
let schemas = vec!;
let ts_file = generate_zod_file;
println!;
Generated output
// Auto-generated by vld-ts — do not edit manually
import { z } from "zod";
export const UserSchema = z.object({
name: z.string().min(2).max(50),
email: z.string().email(),
age: z.number().int().min(0).optional()
});
export type User = z.infer<typeof UserSchema>;
export const EmailSchema = z.string().email();
export type Email = z.infer<typeof EmailSchema>;
Supported JSON Schema features
| JSON Schema | Zod output |
|---|---|
type: "string" |
z.string() |
type: "number" |
z.number() |
type: "integer" |
z.number().int() |
type: "boolean" |
z.boolean() |
type: "null" |
z.null() |
type: "array" |
z.array(...) |
type: "object" |
z.object({...}) |
oneOf |
z.union([...]) |
allOf |
z.intersection(...) |
anyOf |
z.union([...]) |
enum |
z.literal(...) / z.union() |
format: "email" |
.email() |
format: "uuid" |
.uuid() |
format: "date"/"date-time" |
.date() / .datetime() |
minLength/maxLength |
.min()/.max() |
minimum/maximum |
.min()/.max() |
pattern |
.regex() |
description |
.describe() |
nullable (oneOf + null) |
.nullable() |
Examples
License
MIT