JSON to Zod schema
Generate a Zod schema from sample JSON, so the same shape is checked at runtime and inferred as a TypeScript type.
Input
Result
The result will appear here.TypeScript types vanish at compile time; a Zod schema is still there when the response actually arrives, and z.infer turns it back into the type. This generates the schema from a sample with quicktype's typescript-zod renderer. The output imports zod the way version 4 recommends, with import * as z from "zod", declares one schema per object shape, and exports the inferred type next to each. Our tests run the generated code under zod 4 and check that it accepts the very sample it was generated from — the least a generated schema should do.
How it works
- Keys missing from some elements of an array become .optional(); keys that are sometimes null become a union with z.null().
- Schemas are emitted in dependency order, so each nested schema is declared before the object schema that uses it.
- Date detection turns ISO timestamps into z.coerce.date(), which parses the string into a Date; leave it off to keep z.string().
- The schemas are plain z.object calls, so unknown keys are stripped on parse; switch to z.strictObject or z.looseObject by hand if you need otherwise.
Where your data goes
Nowhere. This tool runs entirely in your browser: the text you paste is processed by the page and is never transmitted to a server or written to a log.
This tool is free and needs no account. Its results exist only in your open page and are not saved anywhere.
What it costs
This tool is free, with no sign-in and no points.
Common questions
- Does the output work with Zod 3 as well?
- Yes. The calls it uses — z.object, z.array, z.union, z.null, .optional() and z.coerce.date() — exist in both major versions, and the namespace import works with 3.x too. What changed between versions is error formatting and some advanced APIs, none of which appear in the generated code.
- Why is the top-level schema an array of another schema?
- Because the sample is an array. The element shape gets its own schema — RepoElementSchema for the GitHub sample — and the top-level name is used for the array, so you can validate a single item or the whole list with the same file.
- How strict is the generated schema?
- Exactly as strict as the sample, which is not very. A string field accepts any string, not just the values you pasted, and numbers are z.number() whether or not they were whole. Tighten it afterwards with .int(), z.url(), z.email() or z.enum() wherever your API contract says more than one sample can.
The open-source behind it
This tool runs on glideapps/quicktype, released under Apache-2.0. If you need the same behaviour inside your own program, that is the library to reach for.
glideapps/quicktypeAlso known as
- json to zod
- zod schema generator
- generate zod schema from json
- json to zod online
- zod v4 schema
- typescript runtime validation