Skip to main content
Back to tools

JSON to TypeScript

Generate TypeScript interfaces from a JSON object

About JSON to TypeScript

Produces a TypeScript interface named Root from a JSON sample, updating it as you type. The output is self-contained: nested objects are written inline, empty arrays become unknown[], empty nested objects Record<string, unknown>, and keys that aren't valid identifiers, such as my-key, are quoted. Everything runs in your browser, so pasted API responses never leave your machine.

Category: Converters.

Frequently asked questions

Does it handle deeply nested objects?

▾

Yes, at any depth, but nested objects are written inline inside Root instead of as separate named interfaces. To reuse a nested shape, move that block into its own interface and reference it by name.

How are arrays typed?

▾

Each array is typed from all of its elements: ["a", 1] becomes (string | number)[], objects with different keys become a union of object types, and an empty array becomes unknown[].

What happens with null values?

▾

A null value is typed as null, because the sample doesn't show what the field normally holds. Once you know, replace it with a union such as string | null.

What if the JSON is an array at the top level?

▾

The keys of every object in the array are merged into one Root interface, and a type RootArray = Root[] alias is added. Every field is required and typed from the first object that contains it, so add ? to keys that some items lack, as in email?: string.

Related tools