Each nested object becomes its own named interface, in the order they appear, with names taken from the keys such as User or Address.
Converters
JSON to TypeScript Converter
Paste a JSON response and get TypeScript types for it, with a named interface for every nested object and optional fields worked out from your data.
Paste a JSON sample and matching TypeScript types appear here, with a named type for every nested object.
Types from real data, not guesses.
Writing types for an API response by hand is slow and error-prone. Start from a real sample and adjust from there.
When an array holds several objects, they are combined into one type. A field missing from some of them becomes optional, and mixed values become a union.
A null value becomes | null, and an empty array becomes unknown[] because there is nothing to learn its type from.
Frequently asked questions
Are the generated types guaranteed to be right?
They describe the sample you gave. A field that happens to be a string in your sample might sometimes be a number in production, so review the result and give it a wider sample when you can.
Interface or type?
Both describe object shapes. Interfaces can be extended and merged; type aliases are more flexible for unions. Choose whichever your codebase uses.
How are optional fields decided?
Within an array of objects, any key that is missing from at least one element is marked optional with a question mark.
What about keys that are not valid identifiers?
Keys such as content-type are written as quoted properties, which is valid TypeScript.
