JSON to TypeScript
JSON → typesTurn a JSON sample into named TypeScript interfaces.
Interfaces appear hereEvery element of an array is inspected, not just the first: a field that some records lack comes out optional, and mixed types come out as a union. Identical shapes share one interface rather than being duplicated.
About JSON to TypeScript
Paste a JSON response and get TypeScript interfaces for it. Nested objects become their own named interfaces, arrays of objects are named in the singular — a "categories" array yields a Category interface — and keys that are not valid identifiers are quoted so the output compiles as-is.
The part that makes this worth using rather than eyeballing it is how arrays are handled. Every element is inspected, not just the first. If ninety records have a nickname and ten do not, the field comes out optional rather than wrongly required. If a field is sometimes a number and sometimes a string, you get a union instead of a guess. And two objects with identical shapes share one interface instead of producing near-duplicate definitions.
Treat the result as a strong first draft rather than a finished type. A sample cannot tell you that a field is a union when your sample only ever showed one branch, or that a string is really an enum — only the API's documentation can.
Common questions
This page does the work itself, in this tab. Nothing you paste is sent to a server. Close the tab and no copy remains.