JSON to TypeScript Interface Generator

Generate TypeScript interfaces or type aliases for a JSON payload, one per nested object, ready to paste into your project.

JSON
TypeScript
Runs locally in your browser

About the JSON to TypeScript Interface Generator

Typing an API response by hand is tedious and error-prone. This generator infers the shape from a JSON sample: every object becomes an interface named after its key, arrays are typed by their first item (with the keys of all items merged when the items are objects), integers and decimals both become number, and null values become null. Keys that are not valid identifiers are quoted.

Interfaces are emitted in the order they are discovered, root first, and each is exported. Two objects with different keys under the same key name get numbered names so nothing collides. Choose type aliases instead of interfaces if your codebase prefers them, and set the root name to match the endpoint, for example OrderResponse.

Inference has limits: a field that is null in the sample will be typed as null, and an empty array becomes any[]. Review the output and widen those types where the API allows other values. For a runtime check rather than a compile-time type, generate a schema with the JSON Schema Generator.

How to use

  1. Paste a representative JSON response on the left, ideally one where every field has a non-null value.
  2. Set the Root name and choose interface or type alias.
  3. Copy the generated code into a .ts file and adjust any fields that can be optional or null.

Common questions

Why are all my numbers typed as number, not int?
TypeScript has a single number type. If you need to distinguish integers, add a branded type by hand after generating.
How are arrays of mixed objects handled?
The keys of every object in the array are merged into one interface, so a field that appears in only some items still gets a property. Mark those optional with ? afterwards.
Can it mark fields as optional automatically?
Not from a single sample, because a single sample cannot show which fields are sometimes missing. Merge several samples into one array and generate from that to see the union of keys.
Does it generate classes?
No, only interfaces or type aliases. For classes, use the Java, C# or Kotlin generators, which emit class definitions.