input.json
types.ts
Click Convert to generate TypeScript interfaces.

How JSON to TypeScript conversion works

Paste a representative JSON value and select Convert. A root object becomes a Root interface. Nested objects receive names derived from their property keys, so address becomes Address. Primitive values map to familiar TypeScript types such as string, number, boolean, and null.

Arrays and optional fields

For an array of objects, the generator collects keys from every sample item. A key that is absent from at least one item becomes optional with ?. Primitive arrays become forms such as string[]; mixed primitive samples produce a union array. An empty array becomes unknown[] because the sample contains no evidence about its element type.

Treat the result as a starting point

You can only speculate from the sample you paste. A single successful API response cannot expose a field that only appears on errors, a nullable property that just happens to be set today, or all the allowed string values. The generator uses the first observed value of an object property to determine that property’s type across sampled items, so be careful with heterogeneous arrays.

Use the output to avoid typing boilerplate when looking into an API, then edit it against the actual contract: rename badly generated interfaces, add missing unions and nullability, and work out which fields are actually optional.

TypeScript does not validate runtime data

An interface helps the compiler check your code; it disappears when JavaScript runs. Assigning response.json() to a generated type does not prove that the server returned that shape.

At an external boundary, validate the payload against JSON Schema or a runtime validation library, and expose the validated value to the rest of the application. The runtime schema and the generated interfaces should match the same contract.

When this tool is most useful

  • sketching types while exploring a new endpoint;
  • generating a first draft from a realistic fixture;
  • identifying nested shapes in a large response;
  • comparing a sample with interfaces already in your codebase.

Avoid pasting real access tokens or customer records. Replace values while preserving their types and overall structure.