Types appear here.How to use
Add a JSON sample
Paste a real response or fixture, drop or upload a .json file, use Load URL, or press Try sample to load a product with nested dimensions, an array of variants and a null field.
Set the output
Pick TypeScript or Zod schema, type a Root name such as Product, and set the declaration style, null handling, arrays, optional, readonly and export options. The types update as you type.
Copy or download
Press Copy or Download .ts and paste the types into your project. Rename nested types if the generated names do not suit your code.
Why JSON to TypeScript
- Named types for every nested object, with array items merged and missing keys marked optional.
- Interface or type declarations, or a Zod schema that checks data at runtime.
- Readonly, optional, export, null and array style options match your code style.
- Merges identical shapes into one type, and runs in your browser.
Example: nested JSON to named interfaces
The sample on this page is a product with nested dimensions, a list of tags, an array of variants and a supplier set to null. The second variant has a discontinued flag that the first one lacks.
With the root named Product, the tool writes three types: Product, Dimensions and Variant. Because only one variant has discontinued, that property is optional in Variant. Switch Output to Zod schema and the same structure becomes DimensionsSchema, VariantSchema and ProductSchema, written children first so each constant exists before it is used.
Review the output before relying on it. The generator only sees your sample, so a field that is a string in one response and a number in another is typed as a union only if both forms appear in the sample.
| JSON in the sample | Generated TypeScript |
|---|---|
| "dimensions": {"heightCm": 45, "baseCm": 15} | dimensions: Dimensions; with interface Dimensions { heightCm: number; baseCm: number; } |
| "variants": two objects, one with "discontinued": true | variants: Variant[]; with discontinued?: boolean; in Variant |
| "tags": ["lighting", "office"] | tags: string[]; |
| "supplier": null | supplier: null; |
| "id": 1042 | id: number; |
Interface, type alias or Zod schema
All three describe the same shape. The difference is what you can do with them afterwards.
| Output | Example | Good for |
|---|---|---|
| interface | interface Variant { sku: string; stock: number; } | Object shapes that other interfaces extend |
| type alias | type Variant = { sku: string; stock: number; }; | Unions and mapped types built on top of the shape |
| Zod schema | const VariantSchema = z.object({ sku: z.string(), stock: z.number() }); | Checking API responses and form data at runtime |