JSON to TypeScript Interface Generator
Paste JSON and get TypeScript interfaces: nested objects become named types, array items are merged with optional fields, and nulls become unions.
Paste a JSON response and get TypeScript interfaces you can drop straight into your code. Nested objects become their own named interfaces, arrays of objects are merged so that fields missing from some items are marked optional, and values that are sometimes null become | null unions. The conversion runs in your browser, so private API data is not uploaded anywhere.
How to use this tool
- Paste a representative JSON sample — ideally one where arrays contain several items.
- Set the name of the top-level type (Root by default).
- Choose interface or type alias, and whether to add export.
- Copy the result and rename any generated type names you want to change.
Formula
string → string · number → number · true/false → boolean · null → null · [ … ] → T[] · { … } → interface
Every value is inspected and the types found at the same place are merged. A key present in only some objects of an array gets a ? (optional). Different types at one place become a union such as string | number. Identical object shapes share one interface; array item types are named from the singular of the key (orders → Order). Duplicate keys and numbers outside the supported finite, safe-integer range are rejected; other decimals use JavaScript precision.
Example
The sample user record produces three declarations. Root has id: number, name: string, tags: string[], address: Address, orders: Order[] and manager: null. Address has street, city and postcode, all strings. Order has id: string, total: number, items: number and coupon?: string — optional, because only the second order has a coupon.
Frequently asked questions
Should I use interface or type?
For plain object shapes both work. Interfaces can be extended and merged across declarations; type aliases can also describe unions and tuples. Many style guides prefer interface for object shapes.
Why is a field marked optional?
It is missing from at least one object in an array. If the API always sends it, add more complete sample data or remove the ? by hand.
Why is a field typed as null?
Every sample value was null, so there is nothing else to infer. Replace it with the real type, for example string | null.
Does this check my data at runtime?
No. TypeScript types are erased when compiled. To validate API responses at runtime, use a schema library such as Zod or a JSON Schema validator.
Sources
Last updated: 2026-10-30