UTILS.
Private by default
🛡️

JSON to Zod Schema

Paste a sample JSON value and generate a Zod schema plus an inferred TypeScript type, so one shape validates at runtime and types at compile time.

Your files stay on this device

Files are processed in your browser, never uploaded. The site downloads code and assets to run the tools. No accounts or trackers.

Use Download to save this tool as one HTML file for offline use.

Privacy →
output

About this tool

The JSON to Zod Schema tool turns a pasted JSON sample into a ready-to-use Zod schema and the matching TypeScript type. Zod is the dominant TypeScript validation library, and hand-writing z.object trees for real API payloads is slow and error-prone. This converter parses your JSON with JSON.parse, walks the value recursively, and emits idiomatic Zod: strings become z.string(), integers z.number().int(), other numbers z.number(), booleans z.boolean(), null z.null(), and nested objects their own named z.object({...}) schemas.

Everything runs locally in your browser — your JSON is parsed in-page and never uploaded, so sensitive payloads stay on your device. Arrays infer their element type by deep-merging every element, so an array of objects with slightly different keys produces one schema where keys missing from some elements are marked .optional(). ISO-8601 date-time strings are recognised and emitted as z.string().datetime(). Object keys that are not valid identifiers are safely quoted.

The output is a complete module: an exported const for each object schema (children defined before the parents that reference them) followed by export type Root = z.infer<typeof Root>, so you get compile-time types for free. Use the root-name box to rename the top-level schema, and the missing-key toggle to treat absent keys as .optional() (default) or .nullable(). Copy the result or download it as a .ts file.

Frequently asked questions

How are JSON types mapped to Zod?
string to z.string(), an ISO date-time string to z.string().datetime(), integers to z.number().int(), other numbers to z.number(), booleans to z.boolean(), null to z.null(), arrays to z.array(...), and objects to a named z.object({...}). Empty arrays become z.array(z.unknown()).
How are optional or nullable fields handled?
When an array's elements or merged siblings lack a key, that key is marked .optional(). A value seen as null becomes z.null() or adds .nullable(). The missing-key toggle lets you emit .optional() (default) or .nullable() for keys absent from some samples.
Does it also give me a TypeScript type?
Yes. After the schema it emits export type Root = z.infer<typeof Root>, so the inferred static type is derived from the schema itself — one source of truth for both runtime validation and compile-time types.
Is my JSON uploaded anywhere?
No. Parsing and code generation happen entirely in your browser with JSON.parse and plain JavaScript. Nothing is sent to a server, so you can safely paste private API responses.

More tools