JSON to TypeScript Interface Generator

Paste a JSON sample and get ready-to-use TypeScript types.

🔒 Runs entirely in your browser. Nothing you enter is uploaded or stored.

What is the JSON to TypeScript?

Typing API responses by hand is slow and error-prone. Paste a JSON sample and this JSON to TypeScript converter generates matching interface or type declarations, with a named type for every nested object.

The generator looks at all items in an array, not just the first. If one order has a coupon field and another doesn't, coupon becomes optional (coupon?: string). If a field is sometimes a string and sometimes null, you get the union string | null. Nested types are named from their keys (an orders array produces an Order interface), keys that aren't valid identifiers are quoted, and you can add export or readonly.

How to use the JSON to TypeScript

  1. Paste a real JSON response from your API. Include several array items if you can, so optional fields are detected.
  2. Set the root type name and choose interface or type.
  3. Copy the generated TypeScript into your project and adjust names if needed.

Frequently asked questions

Should I use interface or type?

For object shapes both work. Interfaces can be extended and merged, and many style guides prefer them for public APIs. Type aliases are needed for unions and mapped types. Pick whichever your codebase already uses.

Why is a field typed as unknown[]?

The array was empty in your sample, so there was nothing to infer from. Paste a sample with at least one item, or replace unknown with the correct type by hand.

Can a sample guarantee the types are complete?

No. The types describe the JSON you pasted. Fields your API sends only sometimes may be missing. For untrusted input, validate at runtime with a library such as Zod.