About JSON to TypeScript
Typing an API response by hand is slow and easy to get wrong. Paste an example response and this tool writes the TypeScript interfaces for it: a Root interface for the top level, plus one interface per nested object, named after its key.
Arrays of objects are merged into a single interface, so a key that only some items have becomes optional with ?. Mixed values become unions such as string | number, and empty arrays are typed unknown[] until you know more.
How to use it
- Paste a sample of your JSON into the Input panel.
- Choose Convert to TypeScript as the Output.
- Review the generated interfaces and rename any that need a better name.
- Copy them into your project or download a .ts file.
Frequently asked questions
How are the interfaces named?
From their keys in PascalCase: a "user" object becomes User, and the items of a "categories" array become Category. Duplicate names get a number, such as Meta2.
Why is a property typed null?
The sample only had null for that key, so its real type can’t be known. Replace null with the right type, for example string | null.
What about keys with spaces or dashes?
They are kept and quoted, for example "first name": string, so the interface still matches the JSON exactly.