Skip to content

JSON to TypeScript

Generate TypeScript interfaces from a JSON sample, with nested types, optional keys and unions.

Runs in your browser — nothing you enter is sent to a server.

How the JSON to TypeScript works

Paste a JSON sample — an API response, a config file — and the tool writes TypeScript declarations for it as you type. Each nested object becomes its own named interface, taken from its key in PascalCase, so address becomes Address and the items of orders become Order.

When an array holds several objects, their keys are merged: a key that only some items have becomes optional (qty?: number), and a key with different types becomes a union (string | number). Objects with the same shape share one interface. Choose type aliases if your code style prefers type over interface.

Examples

Nested objects and optional keys

{"id":1,"address":{"city":"Paris"},"items":[{"sku":"A1","qty":2},{"sku":"B2"}]} gives an Address interface with city: string, an Item interface with sku: string and qty?: number, and a Root with items: Item[].

qty is optional because the second item doesn't have it.

An array at the top level

[{"id":1},{"id":2,"note":null}] gives interface RootItem with id: number and note?: null, plus type Root = RootItem[].

Frequently asked questions

Why is a property typed as null?

The sample only had null for it, so the real type is unknown. Replace it with what the field holds when it's set, for example string | null. Paste a fuller sample to get better types.

Does it validate data at runtime?

No. TypeScript types disappear when the code is compiled. To check API responses at runtime, use a schema library such as Zod, or check the fields yourself.

Interface or type — which should I use?

Both describe object shapes equally well here. Interfaces can be extended and merged; type aliases can also name unions and primitives. Follow your project's style.

Is my JSON uploaded?

No. It is parsed and converted in your browser.

JSON Formatter

Format, validate and minify JSON, with the exact line and column of any error.

Developer Tools

JSON Diff

Compare two JSON documents and list every added, removed and changed value by path.

Developer Tools