Convert GitHub Repository API JSON to TypeScript

Use json to typescript to model the GitHub Repos API response — nested owner, license, permissions, and snake_case keys preserved exactly.

Real-World API Schemas

Detailed Explanation

GitHub's REST API Shape

GitHub returns deeply nested resources with snake_case keys, nullable license, and a permissions sub-object. Mirroring it exactly in TypeScript avoids any conversion layer at the fetch boundary.

Example JSON (trimmed)

{
  "id": 1296269,
  "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
  "name": "Hello-World",
  "full_name": "octocat/Hello-World",
  "private": false,
  "owner": {
    "login": "octocat",
    "id": 1,
    "type": "User",
    "site_admin": false
  },
  "fork": false,
  "default_branch": "main",
  "license": { "key": "mit", "name": "MIT License", "spdx_id": "MIT" },
  "permissions": { "admin": true, "push": true, "pull": true },
  "stargazers_count": 80,
  "language": "C",
  "archived": false
}

Generated TypeScript

interface RepoOwner {
  login: string;
  id: number;
  type: "User" | "Organization";
  site_admin: boolean;
}

interface License {
  key: string;
  name: string;
  spdx_id: string;
}

interface RepoPermissions {
  admin: boolean;
  push: boolean;
  pull: boolean;
}

interface Repository {
  id: number;
  node_id: string;
  name: string;
  full_name: string;
  private: boolean;
  owner: RepoOwner;
  fork: boolean;
  default_branch: string;
  license: License | null;
  permissions?: RepoPermissions;
  stargazers_count: number;
  language: string | null;
  archived: boolean;
}

GitHub-Specific Notes

  • License is nullable, not optional — repos without a detected license return "license": null.
  • Permissions is optional, not nullable — the field is omitted entirely for unauthenticated requests.
  • Language can be null for empty repos.
  • Owner type is a closed union of "User" | "Organization" — use a literal union, not string.
  • Keep snake_case in the type. Wrapping fetch with a key-transform helper hides the source of truth from grep and breaks 1:1 mapping with the API docs.

This generated shape pairs cleanly with the GitHub REST API documentation page for Repos, so reviewers can diff your types against the canonical schema in seconds.

Use Case

Building a self-hosted GitHub stars dashboard that pulls repository metadata and needs strongly typed access to stargazer counts, license info, and permissions without depending on @octokit/types.

Try It — JSON to TypeScript

Open full tool