JSON to TypeScript Interface
Paste JSON from an API and get matching TypeScript interfaces, including nested objects and arrays.
How to use the JSON to TypeScript Converter
- Paste your JSONPaste a response from an API or any JSON object or array.
- Set the optionsName the root type, choose interface or type, and add export or readonly.
- Copy the typesPaste the generated TypeScript into your project.
Example
{"id": 42, "tags": ["admin"], "address": {"city": "Kolkata"}} becomes interface Root { id: number; tags: string[]; address: Address; } plus interface Address { city: string; }.
When an array of objects has a field in only some items, such as coupon, it is marked optional: coupon?: string.
Frequently asked questions
How are nested objects handled?
Each nested object gets its own named interface, based on its key: an “address” object becomes interface Address. Arrays of objects are named in the singular, so “orders” becomes Order.
What about null values?
A field that is null in the sample is typed as null. Real APIs often allow null or a value, so you may want to change it to, for example, string | null.
Should I use interface or type?
Either works for object shapes. Interfaces can be extended and merged; type aliases can also describe unions and other complex types. Many teams pick one style and stick to it.