json-typescript-generator
v1.0.0
Published
A CLI to transform JSON to TypeScript Interfaces
Maintainers
Readme
JsonToTypescript
JSON → TypeScript Model CLI
Convert raw JSON into clean, readable TypeScript types or interfaces in seconds.

Features
- One-step generation: paste JSON and press Enter to generate a
.tsfile. - Readable names: nested types are named from JSON keys
e.g.profile→Profile,projects→Project[],settings.notifications→Notifications. - Smart inference
nullbecomesany(andanydominates 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.
Install
npm install -g json-to-typescriptUsage
Interactive (paste JSON)
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 directoryFrom a file
json-to-typescript --model-name Order --input-json ./order.jsonWith options
--interface→ generateinterfaceinstead oftype--no-dates→ don't convert ISO strings toDate--no-color→ plain log output--out path.ts→ specify output file path
Example
Input JSON:
{
"id": 123,
"name": "Patrick",
"profile": { "bio": "Dev", "age": 30 },
"tags": ["typescript", "node"]
}Output:
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
.tsfiles instead of one big file - JSON → Java
- Generate POJOs with optional Lombok annotations.
- JSON → Rust
- Generate
structs with optionalserdeannotations for serialization.
- Generate
- JSON → Python
- Generate Pydantic models (ideal for FastAPI and modern Python backends).
- Java → TypeScript
- Translate existing Java POJOs into matching TypeScript interfaces.
- Config file support to specify which POJOs to include for translation.
- VS Code extension → right-click JSON → Generate TypeScript Interface
- Web playground → paste JSON in browser → copy TS interface
License
MIT © Kevin Gleeson
