JSON

JSON to TypeScript Interface

Paste a sample JSON payload to generate TypeScript interfaces — nested objects, optional fields, and union types, detected automatically.

Indent
Sample JSON
TypeScript Interfaces
Paste or type a sample JSON payload on the left to see its TypeScript interfaces here.

Quick Learn

A TypeScript interface describes the shape of a value at compile time — which properties it has and what type each one is — so the compiler can catch a typo or a wrong type before your code ever runs. When you're working with an API response or a config file, writing that interface by hand means reading the payload and transcribing every field, which is slow and easy to get wrong.

This tool generates it from a real example instead: paste a sample payload and it infers a type for every field, and a named interface for every nested object. When the sample is an array of objects, it looks across every item — a field present in every item stays required, a field that only shows up sometimes becomes optional (key?: type), and a field whose type varies becomes a union (string | null). Everything runs locally in your browser.

Best Practices

  • •Treat the generated interfaces as a first draft — review field names the tool had to guess a type for (empty arrays become unknown[]) and tighten them by hand once you know the real shape.
  • •If your real API response can include fields your sample doesn't have, either merge a few representative samples before pasting, or widen the relevant fields manually after generating.
  • •Repeated shapes (the same object structure appearing in different places) are automatically deduplicated into a single reused interface — if you see fewer interfaces than expected, that's why.
  • •Property names that aren't valid TypeScript identifiers (e.g. "first-name") are automatically quoted in the output — that's expected and valid TypeScript, not a bug.

More JSON Tools

See all JSON tools

Frequently Asked Questions

Is my data uploaded or stored anywhere?

No. The interfaces are generated entirely in your browser from the JSON you paste — nothing is sent to a server or stored anywhere.

How are nested objects named?

Each nested object is named after the property key it was found under (converted to PascalCase), and array items are named using a singularized version of the array's key — e.g. a "tags" array of objects becomes a Tag interface.

Why did some fields end up optional?

When your sample is an array, the tool compares every item. A field marked optional (key?: type) means it wasn't present in at least one of the items — the tool only marks a field required when every item has it.

Why do two different objects share the same interface?

If two objects — even in completely different parts of your JSON — have the exact same set of fields and types, the tool reuses one interface for both instead of generating duplicates.

Does it detect number vs. integer, like the JSON Schema tool does?

No — TypeScript has a single number type for all numeric values, so this tool doesn't distinguish integers from floats the way JSON Schema does.

Want the engineering deep-dives behind tools like this one?