Typing an API response
Paste a real response body and get the interface. Then widen any fields the API documents as optional or nullable.
Generate TypeScript interfaces from a JSON sample in your browser.
Maintained by Roshan.
Converts json sample to typescript in this tab, with nothing sent anywhere.
Find related browser-local tools for nearby tasks without starting another search.
Browse all generatorsWriting a TypeScript interface by hand from a real API response is tedious and easy to get subtly wrong - a mistyped field, a missed nesting, a number where a string should be. Generating it from an actual sample removes the guesswork: paste the JSON your API really returns, and get the interface that matches it. This infers the shape recursively, so a nested object becomes its own named interface rather than an inline blob, which is how you would write it by hand and what keeps the types readable. The inference is deliberately conservative - it describes exactly what the sample contains and does not invent optional fields or unions a single example cannot prove - so the output is an accurate starting point you refine, not a guess dressed up as certainty.
Paste a real response body and get the interface. Then widen any fields the API documents as optional or nullable.
Generate the interfaces from sample data, then refine names and optionality by hand.
Yes. Each becomes its own named interface referenced by its parent, rather than an inline type.
A single sample cannot prove optionality. It types what the example contains; widen fields to optional or nullable yourself.
By their first element. An empty array becomes unknown[], since there is nothing to infer.
Yes. There is a field for the root name; nested interfaces are named from their keys.
Generate Go structs from a JSON sample in your browser, complete with json struct tags.
Generate Python dataclasses from a JSON sample in your browser, with type hints.
Generate a JSON Schema from a sample document in your browser, inferring types and required fields.