How to turn JSON into TypeScript
- Paste a sample of the JSON, such as an API response.
- Name the main type, and choose interface or type.
- Copy the result into your project. It updates as you type.
Need to check the JSON first? Use the JSON formatter.
Turn a JSON sample, like an API response, into TypeScript interfaces or types, with nested types and optional fields.
Need to check the JSON first? Use the JSON formatter.
From your sample JSON: strings, numbers and booleans become string, number and boolean; nested objects get their own interface named after their key; arrays become lists of the types inside them. If objects in an array don't all have a key, it becomes optional (key?).
A key that's null in the sample becomes the type null (or, combined with other values in an array, for example string | null). Paste a sample with real values where you can, for more useful types.
Both describe the same shapes. Interfaces can be extended and merged, and are the usual choice for object shapes; types can also describe unions. Pick what your codebase uses.
No. The types are made in your browser.