Skip to content

JSON to TypeScript converter

Generate TypeScript interfaces from a JSON sample, with one interface per distinct object shape, even inside arrays.

Options

 

Generated TypeScript

 

How it works

This tool infers TypeScript interface definitions from a JSON sample by inspecting each key and value, then outputs exportable interface declarations. Arrays of objects that repeat the same shape, such as a list of API records, generate a single shared interface instead of a duplicate per item.

  1. Paste JSON

    An object, or an array of objects such as an API response.

  2. Name the root interface

    Nested objects get their own interface, named from the field.

  3. Copy the TypeScript

    It updates as you type or change an option.

How shapes are matched and named

Nested objects generate a separate named interface. For example, a field called address containing city and zip becomes an Address interface, and the parent interface references it as address: Address. Interface names are derived by capitalizing the field name.

Every object shape is reduced to a signature made of its sorted property names and types. When two objects anywhere in the JSON share the same signature, such as every item in an array of records, they reuse the same interface instead of generating a new, identically shaped interface with a numeric suffix.

  • Arrays: typed as an element-type array, for example string[] or Tag[]. An array whose elements have more than one distinct shape becomes a union, for example (Cat | Dog)[].
  • Optional properties: off by default, since the sample shows every key as present. Turn on "All properties optional" when your real data sometimes omits fields.
  • Unusual keys: a property name that is not a valid identifier, such as one containing a hyphen, is quoted in the output.

A single sample cannot show every case

Like any schema inference from one example, a field that is sometimes a string and sometimes a number is typed from whichever value appears in your sample, and union types are not detected automatically. Review the output and add union types or string literal types where your real data varies. Everything runs in this page: your JSON, which may contain internal field names or proprietary API shapes, is never sent anywhere.

Frequently asked questions

How do I generate TypeScript interfaces from a JSON API response?

Paste the JSON object or array into the input field, set the root interface name, which defaults to Root, and the interfaces regenerate as you type. The tool inspects each key and value, infers the TypeScript type, string, number, boolean, null, nested interface, or array, and outputs exportable interface declarations ready to drop into your TypeScript project.

Does the TypeScript generator work offline and without sending my data anywhere?

Yes. The entire generation runs in your browser with JavaScript. Your JSON data, which may contain internal field names, data structures, or proprietary API shapes, is never transmitted to any server. The output TypeScript is generated and displayed locally.

How does this tool handle nested JSON objects and arrays?

Nested objects generate a separate named interface. For example, a field called address containing city and zip becomes an Address interface, and the parent interface references it as address: Address. Arrays are typed as element-type arrays, for example string[] or Tag[]. An array of objects that all share the same shape produces one interface, reused for every element, rather than a separate interface per item.

When should I use optional properties in the generated TypeScript interface?

Enable "All properties optional" when some fields in the JSON may be absent on certain objects. This adds a question mark after each property name, for example email?: string, making TypeScript accept objects that omit those fields. By default, all inferred properties are required. If you are modeling an API with optional query parameters or nullable fields, optional props prevents type errors.

What is a major limitation of inferring TypeScript types from a single JSON sample?

Like any schema inference from one example, the generator can only see what is present in the sample. A field that is sometimes string and sometimes number is typed based on whichever value appears in the sample. Union types such as string | number | null are not automatically generated. Review the output carefully and add union types, generics, or more specific string literal types where your actual data varies.