What this does
Generates a Zod schema from a JSON sample, plus az.infer type for each schema. Use it to validate API responses or request bodies at runtime and get the matching static type for free. Nested objects become separate schemas that are declared before they are used.
Example
Input
{
"id": 42,
"name": "Ada",
"verified": true,
"tags": [
"admin",
"dev"
],
"orders": [
{
"sku": "A1",
"qty": 2
},
{
"sku": "B2",
"qty": 1,
"note": "gift"
}
]
}Output with default options
import * as z from "zod";
export const OrderSchema = z.object({
"sku": z.string(),
"qty": z.number(),
"note": z.string().optional(),
});
export type Order = z.infer<typeof OrderSchema>;
export const RootSchema = z.object({
"id": z.number(),
"name": z.string(),
"verified": z.boolean(),
"tags": z.array(z.string()),
"orders": z.array(OrderSchema),
});
export type Root = z.infer<typeof RootSchema>;
How values are mapped
- Strings, numbers, and booleans become
z.string(),z.number(), andz.boolean(). - Arrays become
z.array(...); arrays with mixed element types becomez.union([...]). - A field missing from some objects in an array gets
.optional(); a field that is sometimesnullbecomesz.union([z.null(), ...]). - ISO 8601 timestamps become
z.coerce.date()when date detection is on. Turn Detect dates and UUIDs off to keepz.string().
Things to know
The schema is inferred from your sample, so it describes exactly what you pasted. Integers and floats are both z.number(); add .int() yourself where it matters. The output imports from "zod" in the Zod 4 style (import * as z from "zod"). For plain compile-time types without runtime validation, useJSON to TypeScript.
Privacy
Generation runs in a Web Worker in your browser. The JSON is never uploaded.