About the JSON to Zod
Zod validates data at run time and gives you the TypeScript type of the result. This tool writes the schema from a sample: objects become z.object({ … }), arrays z.array(…), whole numbers z.number().int(), other numbers z.number(), and null becomes z.null(). A value that is sometimes null gets .nullable(). Keys that are not valid identifiers are quoted, an empty array is z.array(z.unknown()) and an empty object z.record(z.string(), z.unknown()).
The items of an array are merged into one schema. A key that is missing from some items gets .optional(), and values of different kinds become z.union([z.string(), z.number()]). With Detect formats, strings that all have the same format get a check: .email(), .url(), .uuid(), .datetime() (with { offset: true } when a value has an offset like +02:00), .date() and IPv4. The detection is strict, so a format is only added when every sample passes the check of Zod itself.
The Zod 3 output also runs on Zod 4, except the IPv4 check. The Zod 4 output uses the newer top-level forms: z.email(), z.url(), z.uuid(), z.iso.datetime(), z.int() and z.strictObject(). Strict objects reject unknown keys instead of removing them. Export inferred type adds export type Root = z.infer<typeof rootSchema>, and nested objects can be declared as separate schemas, in the order that JavaScript needs. A schema from one sample is a draft: review the optional fields and formats.
How to use it
- Paste a JSON sample or open a .json file.
- Set the root name and choose Zod 3 or Zod 4.
- Toggle format detection, strict objects and separate nested schemas.
- Copy the schema or download schema.ts.