Skip to content

Repository files navigation

json-type-genie

Generate clean TypeScript types from JSON files, API responses, or stdin.

json-type-genie is a tiny zero-dependency CLI for turning real JSON samples into TypeScript interfaces. It is useful when you copy an API response from Postman, browser DevTools, curl, or a mock file and want usable types immediately.

Why people use it

  • Converts JSON to TypeScript in one command.
  • Works with files and stdin.
  • Handles nested objects, arrays, optional fields, and weird JSON keys.
  • Supports readonly, no semicolons, no export, and output files.
  • Has a short alias: jtg.

Install

npm install -g json-type-genie

Or run directly:

npx json-type-genie response.json --name ApiResponse

Usage

json-type-genie examples/user.json --name User
cat response.json | jtg --name ApiResponse > api-types.ts
jtg response.json -n ApiResponse -o src/types/api.ts

Example

Input:

{
  "id": 1,
  "name": "Ada",
  "roles": ["admin", "editor"],
  "profile": { "verified": true }
}

Output:

export interface UserProfile {
  verified: boolean;
}

export interface User {
  id: number;
  name: string;
  roles: string[];
  profile: UserProfile;
}

Options

Option Description
-i, --input JSON input file. If omitted, stdin is used.
-o, --output Write TypeScript output to a file.
-n, --name Root type/interface name.
--readonly Generate readonly fields.
--required Do not mark merged array fields optional.
--no-export Omit export.
--no-semicolon Omit semicolons.
--no-banner Omit generated comment.

License

MIT

About

Generate clean TypeScript types from JSON files, API responses, or stdin.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages