JSON to TypeScript Interface Generator

Paste a JSON sample, such as an API response, and get TypeScript interfaces for it, with nested types, optional fields and unions inferred.

Loading tool…

About the JSON to TypeScript

Every nested object gets its own named interface, named from its key in PascalCase: profile becomes Profile, and items of a plural array are singularised, so posts gives Post[]. Identical shapes are declared once and reused, and name clashes get a numeric suffix.

Arrays of objects are merged: all elements are combined into one shape. A key missing from some elements is marked optional (scheduledAt?: string), and a key whose type differs between elements becomes a union such as string | number. null values produce | null, an empty array gives unknown[], and keys that are not valid identifiers are quoted.

Options: the root type name, interface or type aliases, the export keyword and readonly properties. The result is inferred from one sample, so review it: a field that happened to be null in the sample is typed null only. Your JSON is processed in the browser.

How to use it

  1. Paste a JSON sample or open a .json file.
  2. Set the root name and choose interface or type.
  3. Toggle export and readonly.
  4. Copy the TypeScript or download types.ts.

Frequently asked questions

How are optional properties detected?
When an array holds several objects, a key missing from at least one of them is marked with ?. A single object has no optional fields because there is nothing to compare.
Should I use interface or type?
Both describe object shapes. Interfaces can be extended and merged by declaration; type aliases can also express unions. Pick your codebase's convention.
Why is a field typed as null?
It was null in every sample. Add a sample where it has a value, or edit it to e.g. string | null.
Does it generate runtime validation?
No. TypeScript types are erased at compile time; use a schema library such as Zod if you need runtime checks.

Related tools