JSON to TypeScript
Paste a JSON sample to get TypeScript interfaces for it, nested objects and arrays included.
Frequently asked questions
How are optional fields detected?
When an array holds several objects, a key missing from some of them is marked optional (key?: type). Keys whose value is null in the sample become type | null.
What about arrays of mixed types?
They become a union: (string | number)[]. An empty array becomes unknown[], since the sample does not show what goes in it.
Interface or type?
Both describe the same shape. Interfaces can be extended and merged; type aliases can also describe unions. Pick what your codebase uses.