Skip to content
Utilerio

JSON to TypeScript

Turn a JSON sample into ready-to-use TypeScript interfaces.

TypeScript

The result will appear here.

Was this tool useful?

About this tool

Typing an API response by hand is tedious and error-prone: one renamed field and the type silently drifts from reality. This tool infers TypeScript interfaces directly from a real JSON example — the fastest way to get a starting point before you refine it by hand.

Nested objects each get their own named interface, arrays are typed from their elements, and two objects that happen to share a property name but have a different shape get distinct interface names rather than being merged incorrectly.

How to use it

  1. Paste a JSON object or array — a real API response works best.
  2. Set the name for the top-level interface (defaults to Root).
  3. Copy the generated TypeScript and paste it into your project, then adjust the field types the sample couldn't tell you about — an always-empty array, a field that's sometimes null, a union your sample never showed.

Examples

A simple user object

{ "id": 1, "name": "Ada", "roles": ["admin", "editor"] }
interface Root {
  id: number;
  name: string;
  roles: string[];
}

Common problems

A field shows as `null` instead of a useful type.
The sample JSON had `null` for that field, so there is no type information to infer from it. Put a real value in your sample, or widen the generated type by hand, e.g. `string | null`.
Two nested objects got names like `Item` and `Item2`.
They share a property name but have a different set of keys, so merging them into one interface would be wrong. Rename one of the generated interfaces to something more specific.

Frequently asked questions