Turn an API response into TypeScript types

You have a real JSON payload and an empty .ts file. Infer a first draft of interfaces instead of writing field names by hand.

Tools used in this guide

The job

A new endpoint returns a nested object — users, roles, timestamps — and you need TypeScript types before you can write the consuming code. Typing field names by hand is slow and error-prone, especially when the payload is large.

Worked example

Paste {"user": {"name": "Ada", "roles": ["admin"]}} and the tool emits two interfaces: a User interface with name: string and roles: string[], and a Root interface whose user field is User. Nested objects get their own named interface each; arrays produce element types like string[] or a union when the sample mixes types.

Object shapes that appear twice — say every item in an array — are deduplicated into a single interface, so the output stays compact.

Check the draft before committing

Generated types are a starting point, not ground truth. Three common fixes: values that were null in your sample stay null-typed (widen them to the real type); keys missing from this sample never appear (add them as optional); any[] from an empty sample array usually deserves a real element type.

  • Keys that are not valid identifiers ("user-id", "first name") are emitted quoted — that is valid TypeScript.
  • If the JSON is invalid, fix it with the JSON formatter first, then generate.