Zod schemas from a JSON sample
Paste a JSON document and get the Zod schema that validates it, with the TypeScript type inferred from the schema exported next to it. The schema is the source of truth; the type is derived, which is the Zod convention.
Output shape
import * as z from "zod";
export const OrderSchema = z.object({
"sku": z.string(),
"qty": z.number(),
"gift": z.boolean().optional(),
});
export type Order = z.infer<typeof OrderSchema>;
export const CustomerSchema = z.object({
"id": z.number(),
"tags": z.array(z.string()),
"orders": z.array(OrderSchema),
});
export type Customer = z.infer<typeof CustomerSchema>;
Nested schemas come first so each reference is declared before use. Keys are quoted, so property names that are not valid identifiers work unchanged.
What the inference adds
Repeated string values become z.enum([...]). ISO 8601 strings become z.coerce.date(). Both are toggles under Inference. Turn off Integers from numeric strings when the sample has postal codes or ids as strings, or they will come out as z.number() and fail at parse time on real data.
Schema input
A pasted JSON Schema (anything with a top-level $schema) produces a Zod schema whose optionality follows the required array rather than a guess from one sample. For an API with a published schema, that is the better input.
Limits
Zod constraints that a sample cannot reveal, such as .min(), .email(), or .regex(), are not generated. Add them by hand after generation. From a JSON Schema, minimum, maxLength, and pattern are read where the renderer supports them, but not every keyword maps.