Utilumo
LightDarkSystem
Guide1 min readUpdated August 26, 2026

How to generate a Zod schema from JSON

Short answer

A JSON sample can produce a useful starter Zod schema by mapping strings, numbers, booleans, nulls, objects, and arrays to Zod validators. The generated schema should still be reviewed for business rules, enums, length limits, and custom refinements.

Start from a real sample

Use JSON that looks like the data your app actually receives. A single tiny sample can miss optional keys, nulls, empty arrays, and rare variants.

export const UserSchema = z.object({
  id: z.number(),
  email: z.email(),
  tags: z.array(z.string())
}).strict();
JSON sample to Zod schema
Try it: JSON to Zod SchemaPaste JSON and generate a starter Zod schema locally.Open tool
  • Use strict mode when unknown object keys should fail validation.
  • Use passthrough when you want to keep extra keys from upstream APIs.
  • Review string formats; an email-looking sample does not prove every future value is email.
  • Add refinements manually for IDs, ranges, enums, minimum lengths, and cross-field rules.

References

Questions

Can JSON prove every field is required?

No. A sample only shows fields that are present in that sample. Arrays with different object keys can reveal optional fields, but schema review is still needed.

Should I use Zod or TypeScript interfaces?

Use TypeScript interfaces for compile-time typing, and Zod when you need runtime validation of unknown input.

Does this send my data anywhere?

No. Utilumo's developer tools parse and transform input inside the browser tab. Nothing is uploaded, stored, or logged.

Keep reading