You have an API response and you need types for it. Writing interfaces by hand for forty fields is slow, and it's easy to mistype one. Paste the JSON and the interfaces are written for you.
Nested objects become their own named interfaces. Arrays are typed by their contents, including mixed ones. When objects in an array don't all have the same keys, the missing ones are marked optional.
How to use the JSON to TypeScript tool
- Paste a JSON sample.
- Name the main type and choose interface or type.
- Copy the TypeScript into your project.
Popular uses
- Typing a third-party API response
- Adding types to a JavaScript project during migration
- Quick models for a prototype or a test
Tips for the best result
- Use a sample with several array items, so optional and nullable fields are detected.
- A null value gives the type null. Widen it by hand if you know what it can hold.
Quick facts
| Price | Free |
|---|---|
| Works with | JSON → TS |
| Where it runs | In your browser, on your device |
| Account | Not needed |