Schema plus types
Every object gets an exported schema and a matching type via z.infer.
Create runtime validation schemas and TypeScript types from example JSON.
Generate a Zod schema and inferred TypeScript types from JSON. Detects integers, ISO dates, UUIDs, URLs, optional and nullable fields.
{"id":7,"name":"aarav","createdAt":"2026-03-14T09:30:00Z","tags":["a"]}import { z } from "zod";
export const UserSchema = z.object({
id: z.number().int(),
name: z.string(),
createdAt: z.string().datetime({ offset: true }),
tags: z.array(z.string()),
});
export type User = z.infer<typeof UserSchema>;Tip: Use Schema.parse() where data enters your app, then rely on the inferred type everywhere else.
Every object gets an exported schema and a matching type via z.infer.
ISO date-times, dates, UUIDs and URLs get .datetime(), .date(), .uuid() and .url().
Missing keys become .optional(); null values become .nullable().
Nested objects become their own schemas, declared before they are used.
Zod 3. String helpers like .datetime() and .date() need Zod 3.22 or later.
TypeScript types disappear at runtime; Zod validates real data from APIs, forms and environment variables.
Whole numbers in every sample become z.number().int(); any decimal makes the field z.number().
No, the schema is generated in your browser.