JSON to TypeScript Interfaces
Stop writing types for API responses by hand. Paste an example and get TypeScript interfaces for every nested object, with optional and nullable fields worked out from the data.
How to generate TypeScript types from JSON
- 1Paste a JSON example, ideally with several array items.
- 2Name the root type and choose interface or type.
- 3Copy the code or download types.ts.
How the types are worked out
Every item of an array is merged into one type, so a key that's missing from some items becomes optional and a value that's sometimes null becomes nullable. Whole numbers and decimals are told apart, nested objects get their own named types (an “items” array gets an “Item” type), and objects with the same shape share one type.
TypeScript specifics
Optional keys get a ?, nullable values get | null, and keys that aren't valid identifiers are quoted. Empty arrays become unknown[], since there's nothing to infer from; add an item to get a real type.
Check the result
Types can only be as complete as the example. A key that's always present in your sample but optional in real data won't be marked optional, so review the output against your API docs.
Frequently asked questions
- Is my data uploaded?
- No. Everything runs in your browser, so the JSON never leaves your device.
- Interface or type?
- Either works for describing JSON. Interfaces are the common choice; pick type if your codebase uses type aliases.
- Can it validate data at runtime?
- TypeScript types disappear when compiled. For runtime checks, use JSON to Zod.