Developer / Types
JSON to Zod Schema Converter
Generate a Zod schema and its TypeScript type from a JSON sample, with nested objects, arrays, optional and nullable fields, and integers.
JSON to Zod Schema Converter: Each object in the sample becomes a z.object schema, exported with a type inferred from it, and nested objects get their own named schemas. Objects in an array are merged: keys missing from some get .optional(), keys that are sometimes null get .nullable(), and whole numbers get .int(). The generated schemas were checked by parsing their own samples with Zod. Runs 100% locally in your browser with zero server file uploads.
- Category
- Developer tools
- Runs
- In your browser
- Cost
- Free · no sign-up
- Availability
- Ready to use
Runs entirely in your browser
TypeScript
import { z } from "zod";
export const AddressSchema = z.object({
city: z.string(),
zip_code: z.string(),
});
export type Address = z.infer<typeof AddressSchema>;
export const UserSchema = z.object({
id: z.number().int(),
user_name: z.string(),
avatar_url: z.string(),
score: z.number(),
tags: z.array(z.string()),
address: AddressSchema,
manager_id: z.number().int().nullable(),
nickname: z.string().optional(),
});
export type User = z.infer<typeof UserSchema>;
export const UserListSchema = z.array(UserSchema);
Each object gets a schema and an inferred type. Keys missing from some objects get .optional(), keys that are sometimes null get .nullable(), and whole numbers get .int(); loosen any rule your API does not guarantee.
Using the schema
Call Schema.parse(data) to validate and throw on bad data, or Schema.safeParse(data) to get a result you can check without try and catch. The exported type, from z.infer, stays in step with the schema as you edit it.
If you only need compile-time types, JSON to TypeScript gives plain interfaces; to validate against an existing JSON Schema, use the JSON Schema validator.
Tightening the generated rules
The sample shows only what it contains, so treat the schema as a starting point: add .email(), .url(), or .datetime() to strings where they apply, z.enum([...]) for fields with a fixed set of values, and .min() or .max() where your data has limits.
How to use it
- Paste a JSON sample, ideally an array with several typical records.
- Name the top-level type.
- Copy the schemas and use them to validate data at runtime.
Privacy & limitations
The JSON is converted in your browser and never uploaded.
Related tools
Frequently asked questions
Why use Zod instead of a TypeScript interface?
An interface disappears when the code is compiled, so it cannot check data at runtime; a Zod schema checks the data and gives you the same type with z.infer.
Should integers really be .int()?
Only if your API promises whole numbers. If a price or score can have a fraction, remove .int() even when the sample has only whole numbers.
Does it handle strings like dates or emails?
They are typed as z.string(); add refinements such as .email(), .url(), or a date check where your data needs them.
Free tool · runs in your browser · no account required