JSON to TypeScript
Generate TypeScript interfaces from a JSON sample.
About this tool
Paste a JSON response and get TypeScript interfaces for it. Nested objects become their own named interfaces, arrays of objects are merged so optional fields are marked with ?, and mixed values become union types.
How to use it
- Paste a sample JSON response from your API.
- Set the name of the root type, for example User or OrderResponse.
- Choose interface or type declarations, and whether to export them.
- Copy the generated TypeScript into your project and adjust anything the sample couldn’t show.
Questions
- How are optional fields detected?
- When an array contains several objects, a field that is missing from some of them is marked optional with ?. A single object can’t reveal optional fields, so give a sample with several items if you can.
- Why is a field typed as null?
- Because it was null in the sample, so its real type is unknown. Replace it with something like string | null once you know what the API returns.
- Should I use interface or type?
- Both work for describing JSON. Interfaces can be extended and merged and give slightly clearer error messages; type aliases are needed for unions. Pick whatever your codebase already uses.
- Does it validate data at runtime?
- No. TypeScript types disappear when compiled. To check data at runtime, use a schema library such as Zod alongside these types.
Something not working, or a result looks wrong? Report a problem with this tool