Convert JSON to TypeScript type definitions. Pipe it, pass a file, or grab from clipboard.
npm install -g json2typesOr use directly with npx:
npx json2types input.json# From a file
json2types data.json
# From stdin
echo '{"name": "Alice", "age": 30}' | json2types
# From clipboard
json2types --clipboard
# Custom root type name
json2types data.json --name UserInput:
{
"id": 1,
"name": "Alice",
"email": null,
"address": {
"street": "123 Main St",
"city": "Springfield"
},
"tags": ["admin", "user"]
}Output:
interface Address {
street: string;
city: string;
}
interface Root {
id: number;
name: string;
email?: unknown;
address: Address;
tags: string[];
}| Flag | Description |
|---|---|
--name <name>, -n |
Name for the root type (default: Root) |
--clipboard, -c |
Read JSON from system clipboard |
--help, -h |
Show help |
--version, -v |
Show version |
- Nested object detection with named interfaces
- Array element type inference
- Null values become optional properties
- Mixed-type arrays become union types
- Keys with special characters are quoted
- Zero runtime dependencies
MIT