How to Convert Nested JSON to TypeScript

API payloads are usually nested. This converter walks objects and arrays, names inner types from JSON keys, and reuses a type when two objects share the same shape.

Nested objects become separate named types.
{
  "id": 1,
  "profile": {
    "city": "London",
    "score": 9.5
  }
}
// Generated locally in your browser. No data was sent to a server.

export interface Profile {
  city: string;
  score: number;
}

export interface Account {
  id: number;
  profile: Profile;
}
An array of objects merges keys and marks missing ones optional.
{
  "projects": [
    { "title": "Engine", "status": "complete" },
    { "title": "Notes" }
  ]
}
// Generated locally in your browser. No data was sent to a server.

export interface Project {
  title: string;
  status?: string;
}

export interface Workspace {
  projects: Project[];
}

Edge cases

  • Deep nesting is supported; each object level gets a name derived from its key (singularized for arrays).
  • Empty arrays cannot infer an element shape, so the element type is unknown.
  • A root JSON array still works: the item type is named, and the root is a type alias for that item array.

Open the converter with your own payload when you want to copy or download the generated .ts file.