JSON to TypeScript
runs in your browserno sign-upfree
Generate TypeScript interfaces or types from JSON, with nested objects and optional fields.
4 types generated
About this tool
This tool generates TypeScript interfaces from a JSON example, such as an API response. Nested objects get their own interfaces named after their keys, all items of an array are merged into one type, keys that only some items have become optional (?), and identical shapes share one interface. Choose interface or type and whether to export them.
How to use
- Paste a JSON example into the JSON box.
- Set the name of the main type and choose interface or type.
- Copy the TypeScript or download it as a .ts file.
FAQ
Why is a field optional (?)?
Because it is missing from at least one object in an array. For example, if only some tools have "featured", the field becomes featured?: boolean.
What happens with null values?
A field that is null in your example gets the type null. If the same field has a real value elsewhere, it becomes a union such as string | null. Give an example with a real value for the best result.
How are the interfaces named?
After their key in PascalCase: "owner" becomes Owner, and items of an array are named in the singular, so "tools" becomes Tool and "categories" becomes Category.
Is my JSON uploaded?
No. The types are generated in your browser, so your data never leaves your device.