Turn a JSON sample into a Zod schema in one step. Paste an API response or config file and get z.object schemas for every nested object, with arrays of objects merged so missing fields become optional and null values become nullable — plus email, UUID, URL and date refinements and z.infer types if you want them. Copy the result into your TypeScript project. It's free, runs in your browser, and your JSON never leaves your device.
| JSON value | Zod |
|---|---|
| "text" | z.string() |
| 42 | z.number().int() |
| 4.2 | z.number() |
| true | z.boolean() |
| null | .nullable() / z.null() |
| [ … ] | z.array(…) |
| { … } | z.object({ … }) |
| missing in some items | .optional() |
It compares every object in an array. A key that's missing from some of them is marked .optional().
Yes, if every value of a field matches — .email(), .uuid(), .url(), .date() or .datetime(). Turn it off for plain z.string().
When every sample value is a whole number. A single decimal anywhere makes it z.number().
Yes — the generated API (z.object, z.array, z.union, .optional, .nullable) is the same in Zod 3 and 4.
No. Conversion happens in your browser.
The converter infers one shape that covers the whole sample rather than reading only the first value it sees. Every object found in an array is merged: a key present in all of them becomes a required field, a key missing from some becomes .optional(), and a value that is sometimes null becomes .nullable() — the difference between a schema that validates the real API response and one that rejects the second item. Numbers are z.number().int() when every sample is a whole number and z.number() otherwise; arrays with mixed element types become a z.union; nested objects become their own named schemas declared before the schemas that use them, with names taken from the key and singularized for array items (posts → Post). Optionally, strings that all match a format are refined with .email(), .uuid(), .url(), .date() or .datetime({ offset: true }). Keys that aren't valid JavaScript identifiers are quoted, objects can be made .strict() so unknown keys fail validation, and each schema can export its z.infer type. The schema reflects the sample, so the page reminds you to check it against the real contract.