JSON to TypeScript Types — Free Online
Infer TypeScript types or a Zod schema from JSON. Handles nested objects, arrays, and nulls—runs in your browser.
How it works
- Paste JSON, choose a root type name, and generate TypeScript or Zod. Array items are merged; missing keys become optional.
About JSON to TypeScript
Inferring types from JSON
This tool walks a JSON value and emits a TypeScript type—or a Zod schema—that describes its shape. Nested objects stay nested; array elements are merged into one element type.
When some array items omit a key, that field becomes optional. Null values become nullable. Inference runs locally; review the result before shipping it.
Generate types in code
- TypeScript
type Root = { name: string; tags: string[]; meta?: { ok: boolean } | null; };- Zod
import { z } from "zod"; export const RootSchema = z.object({ name: z.string(), tags: z.array(z.string()), meta: z.object({ ok: z.boolean() }).nullable().optional(), });
JSON to TypeScript FAQ
- How are array element types merged?
- Each element’s shape is merged. Shared fields keep a common type; fields missing on some elements become optional; nulls become nullable.
- Can I output a Zod schema instead?
- Yes. Choose Zod schema in the output control. The result imports zod and exports both the schema and an inferred type.
- Is the inferred type always exact?
- No. Inference reflects the sample you pasted. Extra runtime fields or narrower unions need manual edits.