JSON to TypeScript Interface Generator

Paste a JSON sample and get inferred TypeScript interfaces, with nested objects extracted into their own named types. Runs entirely in your browser.

TypeScript

export interface Profile {
  city: string;
  verified: boolean;
}

export interface Order {
  id: number;
  total: number;
}

export interface Root {
  id: number;
  name: string;
  active: boolean;
  roles: string[];
  profile: Profile;
  orders: Order[];
}

Inferred from a single sample: a key missing from the sample can't be inferred, and every field is treated as required. Mark optional fields with ? and widen literal types as needed.

About this tool

Hand-writing TypeScript types for an API response is tedious and error-prone, so this generator does the first pass for you: paste a representative JSON sample and it infers a set of interfaces describing its shape. Nested objects are extracted into their own named interfaces (an `address` object becomes an `Address` interface and is referenced from the parent), arrays infer their element type โ€” merging to a union when the elements differ โ€” and a root array produces a clean `type Root = RootItem[]` alias. The result is a starting point you refine, and the tool is honest about the limits of inference from one sample: a field that does not appear in the sample cannot be inferred, every field is assumed required (so add `?` where values are optional), and specific strings are widened to `string` rather than literal unions. It is ideal for quickly typing a third-party response or a config file. Everything runs locally, so private payloads stay in your browser.

How to use it

  • Paste a representative JSON sample.
  • Optionally rename the root interface.
  • Copy the generated interfaces into your project.
  • Refine: mark optional fields with ?, narrow types, and add fields the sample didn't include.

Frequently asked questions

How are nested objects handled?
Each nested object becomes its own exported interface, named from its key in PascalCase, and the parent references it by name. This keeps the output readable and reusable instead of producing one giant inline type.
How are arrays typed?
The element type is inferred from the array contents. If all elements share a type you get `T[]`; if they differ you get a union like `(string | number)[]`. An empty array becomes `unknown[]` since there is nothing to infer from.
Why are all fields marked as required?
A single sample cannot reveal which fields are optional โ€” only which were present. Treat the output as required-by-default and add a `?` to any field that may be absent in other responses.
Why is my "status": "active" typed as string, not a literal?
Inference widens specific strings and numbers to their base type (string, number) because one sample does not tell us the full set of allowed values. If you know the finite set, replace it with a literal union like `"active" | "inactive"`.
Can it infer optional or nullable fields across multiple samples?
Not from one sample. For richer inference (optionality, nullability, unions across many records) feed a representative example that includes the variations, or use a dedicated codegen step against a schema. This tool targets the quick single-sample case.
Is my JSON uploaded?
No. Parsing and type generation run entirely in your browser with no network request.

Related tools