How to use
- Paste a JSON object or array, for example an API response.
- Give the root type a name and choose interface or type.
- Copy the generated declarations into a .ts file.
Generate TypeScript interfaces from JSON
Writing TypeScript interfaces for an API response by hand is slow and error prone. This converter infers the shape of your JSON, creates a named interface for every nested object, merges the objects inside arrays to find optional properties and builds union types when a value has more than one type. The output compiles as-is.
When an array contains several objects, their keys are merged. A key that is missing from some of the objects is marked optional with a question mark. You can also mark every property optional.