Updated August 26, 2026
Zod Schema Patterns Reference
When you generate a schema from JSON, these are the Zod patterns you will review most before using the schema for runtime validation.
Generated schema patterns
| JSON shape | Zod pattern | Review |
|---|---|---|
| String | z.string() | Add min, max, regex, email, URL, or UUID checks when needed. |
| Number | z.number() | Add integer, min, max, or finite constraints manually. |
| Boolean | z.boolean() | Useful for flags and toggles. |
| Null | z.null() | Use unions or nullable patterns when a field can be null or typed. |
| Array | z.array(...) | Empty arrays cannot reveal the item schema. |
| Object | z.object({ ... }) | Choose strict, strip, or passthrough behavior for unknown keys. |
| Missing in some array records | .optional() | A missing key in sample data may mean optional, incomplete, or bad sample data. |
Strict object with inferred type
export const UserSchema = z.object({
id: z.number(),
email: z.email()
}).strict();
export type User = z.infer<typeof UserSchema>;References
Questions
Is a generated Zod schema enough for production?
Usually no. Generated schemas are a fast start, but production validation needs reviewed constraints and domain rules.
Should unknown keys be strict or passthrough?
Use strict when extra keys should fail, passthrough when upstream APIs can add fields you want to keep, and strip when extra keys should be removed.