Declare as

Result

Paste sample JSON to generate TypeScript types.

How to use this tool

  • Paste a JSON sample, such as an API response.
  • Choose a name for the root type and whether to declare interface or type.
  • Copy the result or download a .ts file.

How it works

Each object becomes an interface named after its property (address → Address). Arrays of objects are merged into one item type (orders → Order): a property missing from some items becomes optional (?), and a property with different kinds of values becomes a union such as string | number. Objects with exactly the same shape share one interface. Keys that are not valid identifiers are quoted.

Example

An array with varying items

{"orders": [{"id": 1, "total": 9.5}, {"id": 2, "note": "x"}]} gives orders: Order[] and interface Order { id: number; total?: number; note?: string; }.

Privacy and limitations

  • Everything runs in your browser; nothing you enter is uploaded or stored.
  • Types come from the sample only. A value that is null in the sample is typed as null; a property absent from every sample cannot be known.
  • Dates arrive in JSON as strings and are typed as string.

Frequently asked questions

Should I use interface or type?

Either works for object shapes. Interfaces can be extended and merged; type aliases can also describe unions. Many teams pick one style for consistency.

Why is a field typed as null?

It was null in your sample. Edit it to the real type, such as string | null, or paste a sample where the field has a value.