BackendBench
Coffee
Free tool

JSON to TypeScript

Paste a JSON sample and get TypeScript interfaces. Nested objects become their own types, merged arrays get optional fields.

TypeScript

Typing an API response

When you call a JSON API from TypeScript you want a type for the response so the compiler can catch typos and the editor can autocomplete fields. Write it by hand for a big payload and you will make mistakes; generate it from a real sample and adjust the few places that need a human decision.

Working in Java instead? Try the JSON to Java converter.

Frequently asked questions

Interface or type alias?

Both describe object shapes. Interfaces can be extended and merged; type aliases can also express unions. For plain API response shapes either is fine, so pick one and stay consistent.

Why are some fields optional?

When you paste an array of objects, a field missing from some of them is marked optional (?), because it may not be present.

How are null values typed?

A field that is null in your sample is typed null. Tick "Optional for null" if the real field may be missing or a value; widen it by hand when you know the type.

Does it validate data at runtime?

No. TypeScript types disappear at runtime. Use a validator such as Zod if you need to check untrusted responses.

More tools you might need