How do you turn JSON into TypeScript types?
TypeScript checks the shape of your data while you code. When you receive JSON from an API, you need a type that describes it. Writing that by hand for a large response is slow and easy to get wrong.
This tool reads a sample and infers the types. Nested objects get their own named interfaces, arrays become typed arrays, a key missing from some items becomes optional, and mixed values become a union. The sample produces User, Address and Order, with coupon marked optional on Order.
How to use the JSON to TypeScript Converter
- Paste a sample JSON object or array.
- Name the root type, for example User.
- Choose interface or type, and whether to export.
- Copy the generated TypeScript.