JSON to Zod
Convert JSON objects or arrays into Zod schemas with accurate types, optional fields, nested structures, and TypeScript type inference — all processed in your browser.
Read the full guide1import { z } from "zod";23export const schema = z.object({4user: z.object({5id: z.number().int(),6name: z.string(),7email: z.string().email(),8isActive: z.boolean(),9roles: z.array(z.string()),10profile: z.object({11age: z.number().int(),12address: z.object({13city: z.string(),14zip: z.string(),15}),16}),17lastLogin: z.string().datetime(),18}),19});20export type Schema = z.infer<typeof schema>;21
JSON to Zod converts API responses, fixture files, and pasted JSON into ready-to-use Zod schemas for runtime validation in TypeScript and JavaScript projects. Type inference, format detection (email, URL, UUID, datetime), nested objects, arrays, unions, and unknown-key strategies are all configurable so the output drops directly into your codebase.
Hand-writing Zod schemas for every API endpoint is repetitive and error-prone. A single typo between the schema and the API response breaks runtime validation in production. This tool reads the actual JSON shape and emits a schema that matches — saving hours per integration and eliminating the drift between docs and reality.
.json file..ts file ready for import { z } from "zod".Input JSON card hosts three input tabs: Paste content for direct text, Extract from URL for public JSON endpoints (server-proxied to bypass CORS), and Upload JSON for local .json/.txt files up to 5 MB.
Output Zod Schema renders the generated TypeScript code in a compact line-numbered viewer with Copy and Download .ts actions. The Type Preview tab shows the inferred TypeScript shape so you can verify the schema matches before committing.
Zod Options control schema style, variable name, type inference, unknown-key handling, optional-field strategy, descriptions, enum detection, and pretty print.
Advanced exposes indent size for the generated code.
z.infer<typeof schema>; TypeScript interface emits a separate type alias for editors that struggle with deep z.infer chains.null values into .nullable()..nullable() coverage.Pasted JSON and uploaded files are converted entirely in your browser. The Extract from URL tab is the only path that touches the server, and only to proxy the URL you supply so CORS does not block direct fetches. Nothing is stored.
The generator inspects sample values: emails become z.string().email(), URLs become z.string().url(), UUIDs become z.string().uuid(), ISO date-times become z.string().datetime(), and YYYY-MM-DD strings become z.string().date(). Disable Auto-detect string formats in Advanced to get plain z.string() everywhere.
strip() drops unknown keys silently (Zod default). passthrough() keeps them. strict() throws if extra keys appear. catchall(z.any()) types them as any. Pick based on whether your downstream consumer wants to ignore, preserve, or reject extra fields.
Arrays of one type produce z.array(itemSchema). Heterogeneous arrays produce z.array(z.union([...])). When Use enums for arrays is on and every item is the same string from a small set, the schema becomes z.array(z.enum([...])).
Optional fields = Smart marks fields whose value is null in the sample as .nullable(). Optional fields = Optional all wraps every field in .optional(). The default Required keeps the JSON shape exact.
Yes. Click Download .ts. With Type inference set to Infer from schema, the file also exports a Schema = z.infer<typeof schema> alias. With TypeScript interface, a type definition is generated alongside.