Paste JSON, get a typed Zod schema — AI output validation ready.
import { z } from 'zod'
export const Schema = z.object({
"name": z.string(),
"born": z.number().int(),
"verified": z.boolean(),
"tags": z.array(z.string()),
"profile": z.object({
"era": z.string(),
"fields": z.array(z.string()),
}),
})
export type Schema = z.infer<typeof Schema>🧬 Integers become z.number().int(); mixed arrays emit z.union with up to 3 sample shapes; empty arrays fall back to z.unknown. Keys observed as null emit z.null() — widen those by hand if real values can appear, and add .optional() where APIs omit fields.
Structured-output APIs promise JSON; Zod verifies shape at runtime and gives you the TypeScript type for free via z.infer. This converter turns one example payload into that schema instantly.
Integers get .int(), nested objects nest z.object, arrays of mixed types produce z.union with up to three sample shapes. The export includes both the schema and the inferred type.
JSON samples cannot reveal optionality — a key present in your example becomes required. Add .optional() where APIs omit fields; keys sampled as null emit z.null(), so widen those by hand if real values can appear.
Pass zodResponseFormat(schema) (OpenAI SDK) or feed the JSON Schema equivalent via structured outputs. Validation failures then surface as parse errors instead of silent shape bugs.
More tools you might find useful
Rank every major model by your real monthly API bill.
Per-request and monthly API costs across 17 models, side by side.
Pull every ``` code block out of Markdown or AI answers.
Form-built tool definitions → clean tools JSON for LLM APIs.