A CLI to transform JSON to TypeScript Interfaces
npm install json-typescript-generator


Convert raw JSON into clean, readable TypeScript types or interfaces in seconds.
- One-step generation: paste JSON and press Enter to generate a .ts file.
- Readable names: nested types are named from JSON keys
e.g. profile → Profile, projects → Project[], settings.notifications → Notifications.
- Smart inference
- null becomes any (and any dominates unions).
- ISO-like date strings become string | Date.
- Arrays of short token-like strings become string-literal unions, e.g. ("admin" | "editor")[].
- File naming: output file uses the model name lowercased, e.g. User → user.ts.
- No dependencies: single-file Node CLI.
``bash`
npm install -g json-to-typescript
bash
json-to-typescript
Prompts:
Model name (e.g., User, OrderItem): User
Paste JSON and press Enter when done:
{ ...your JSON... }
=> generates user.ts in the current directory
`$3
`bash
json-to-typescript --model-name Order --input-json ./order.json
`$3
- --interface → generate interface instead of type
- --no-dates → don't convert ISO strings to Date
- --no-color → plain log output
- --out path.ts → specify output file pathExample
Input JSON:
`json
{
"id": 123,
"name": "Patrick",
"profile": { "bio": "Dev", "age": 30 },
"tags": ["typescript", "node"]
}
`Output:
`ts
export type Profile = {
age: number;
bio: string;
};export type User = {
id: number;
name: string;
profile: Profile;
tags: ("typescript" | "node")[];
};
`Contributing
PRs welcome!
---
Future Enhancements
- Nested file output → split models into multiple
.ts files instead of one big file
- JSON → Java
- Generate POJOs with optional Lombok annotations.
- JSON → Rust
- Generate structs with optional serde` annotations for serialization.
---
MIT © Kevin Gleeson