A worked example, rendered from real sample data. Sign in to run the tool on your own input.
{"id":1,"email":"ada@example.com","roles":["admin","editor"],"verified":true,"status":"active","profile":{"name":"Ada","age":36,"joinDate":"2024-01-15"}}import { z } from "zod";
export const MySchema = z.object({
"id": z.number().int(),
"email": z.string(),
"roles": z.array(z.string()),
"verified": z.boolean(),
"status": z.string(),
"profile": z.object({
"name": z.string(),
"age": z.number().int(),
"joinDate": z.string(),
}).strict(),
}).strict();
export type MySchema = z.infer<typeof MySchema>;
// Parse and validate:
// const data = MySchema.parse(jsonInput);
// const result = MySchema.safeParse(jsonInput); // Returns { success, data, error }
Derive a runtime-validatable Zod schema from a JSON sample. Part of the DevTools Surf developer suite. Browse more tools in the Converters collection.