Turn a sample response into types
Most API work starts the same way: you have a JSON response and need a type for it. Paste the response on the left and the right side shows the matching TypeScript, ready for a .ts file. Nothing has to be typed by hand, and a payload with ten levels of nesting takes as long as one with two.
From payload to declaration file
- Paste your JSON into the left box, or press Sample to see how it works.
- Set the name of the main type, for example
UserorApiResponse. - Choose between
interfaceandtype, and tick export or read-only if you want them. - Check the result on the right. A syntax error is reported in place of the types.
- Use Copy or Download .ts to take the code.
How the types are worked out
- Strings, numbers, booleans and null map to the matching TypeScript type.
- A nested object becomes its own interface, named after its key in PascalCase. The key
shipping_addressgivesShippingAddress. - For arrays, all elements are merged. A key that appears in only some of them is marked optional with a question mark, and values of different kinds become a union such as
string | number. - Two objects with exactly the same shape share one interface instead of producing two copies.
- An empty array gives
unknown[], an empty object givesRecord<string, unknown>.
Limits of guessing from one sample
A sample can only show what it contains. A field that was always filled in your example may be null in production, and a number that looks like an id may in fact be a string elsewhere. Dates arrive as strings, so they are typed as string. Treat the output as a first draft and tighten it by hand, or validate real responses at runtime, if the data comes from outside your control.
Your payload stays private
The conversion runs in the page. Production responses, tokens and personal data in a pasted sample are not sent to a server, which makes it fine to use with real data.