JSON to TypeScript Interface

Generate TypeScript interfaces from sample JSON data.

What This Tool Does

This tool inspects one sample JSON value and infers matching TypeScript interface declarations from it. The outermost object is always named Root. For every nested object it encounters, it generates a separate, named interface rather than inlining the shape — the name is built from the immediate parent interface's name plus the title-cased property key. So a Root object with an address key produces a standalone RootAddress interface, and if that address object itself had a nested geo key, that would become RootAddressGeo, and so on down the tree.

Arrays are typed from their first element only: an array of strings becomes string[], an array of objects becomes SomeName[] with SomeName generated as its own interface, and an empty array — since there's nothing to inspect — becomes unknown[]. Primitive values map to JavaScript's own typeof result (string, number, boolean), and null is emitted as the literal type null. When the output contains multiple interfaces, Root is always printed first, followed by the nested interfaces in the order they were discovered.

How to Use It

  1. Paste a representative sample of your JSON — an API response body, a config object, or a saved payload — into the Input box.
  2. Click Run.
  3. The generated Root interface, followed by any nested interfaces it references, appears in the Output box.
  4. Copy the interfaces into your .ts file, and rename Root to something meaningful for your codebase (e.g. User, OrderResponse).
  5. Review the output for optional fields, nullability, and array item variation before treating it as final — see Limitations below.

Worked Example

Input:

{
  "id": 1,
  "name": "Ada",
  "address": { "city": "Berlin" },
  "tags": ["a", "b"]
}

Output:

interface Root {
  id: number;
  name: string;
  address: RootAddress;
  tags: string[];
}

interface RootAddress {
  city: string;
}

Notice the naming: because address is a key on Root, its generated interface is named RootAddress — the parent interface's name followed by the title-cased key. The tags array is typed from its first element ("a", a string), producing string[] rather than a separate interface, since string arrays don't need one.

Common Use Cases

Limitations

This tool infers types from a single example value — it has no visibility into any other possible response your API or data source might produce. Be aware of the following before using generated output in production:

Treat the output as a strong first draft, not a final type definition — always review it against your actual API documentation or several sample payloads.

FAQ

Does it detect optional properties?

No. Only the fields present in the JSON you paste in are considered, so all generated properties are required. Add ? manually for fields that can be missing.

What happens with an empty array?

It's typed as unknown[], since there's no first element to infer a type from. Replace unknown once you know what the array will actually hold.

How are nested interfaces named?

Using the pattern <ParentInterfaceName><TitleCaseKey>. The outermost object is always Root, so a nested address object becomes RootAddress, and nesting further down chains the same way (e.g. RootAddressGeo).

Does it handle null values correctly?

Not fully. A null sample value is typed as the literal null rather than a union such as string | null. Widen these types by hand based on what the field can actually contain.

Is my data uploaded anywhere?

No. Generation happens entirely client-side in your browser — nothing is sent to a server or stored.

Related Tools & Guides

Partner tools