JSON to Zod
Turn JSON examples into Zod schemas for runtime validation.
Turn JSON into Zod schemas
Generate a Zod schema from JSON when you want a runtime validation schema for an API response, a Node handler, or a Next.js route. Nested objects and arrays map to z.object and z.array. The file starts with import { z } from "zod";. Rename the root schema, then copy or download it. The sample stays in the browser.
TypeScript types describe data at compile time, while Zod schemas can validate data at runtime. If you want interfaces instead of runtime validation, use JSON to TypeScript. In a top-level array of objects, a key that some items omit is marked .optional(). Arrays nested inside an object become a z.union of separate object schemas instead. Email, UUID, and datetime formats are not inferred, and a numeric string is not coerced into a number—it stays z.string() until you tighten the schema.
Common questions
Does this validate my API response automatically?
No. It writes a schema from the sample you paste. You still call that schema from your own code when a response arrives.
How are optional fields generated?
A missing key becomes .optional() only when the pasted JSON is a top-level array of objects and at least one object omits that key. Keys on a single object are required. When an array is nested inside an object, objects with different keys become a z.union of separate object schemas.
Does it detect email, UUID, or date formats automatically?
No. Those values stay strings. Add checks such as email or UUID yourself if you need them, and date-like strings are not turned into dates.
Related tools
- JSON
JSON Minifier
Remove whitespace from JSON without changing its structure.
Coming soon