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.
- 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.
npm install -g json-type-genieOr run directly:
npx json-type-genie response.json --name ApiResponsejson-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.tsInput:
{
"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;
}| 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. |
MIT