Generate TypeScript interfaces from JSON data or API responses. Auto-type your APIs instantly. Free CLI tool for TypeScript developers.
Generate TypeScript interfaces from JSON. Stop writing types by hand.
npm install -g @lxgicstudios/json-to-ts
npx @lxgicstudios/json-to-ts data.json
npx @lxgicstudios/json-to-ts response.json -n User
npx @lxgicstudios/json-to-ts https://api.example.com/users -n User
curl https://api.example.com/data | npx @lxgicstudios/json-to-ts -n ApiResponse
npx @lxgicstudios/json-to-ts api.json -o src/types/api.ts
Input JSON:
{
"id": 1,
"name": "John",
"email": "[email protected]",
"address": { "city": "NYC" },
"tags": ["dev", "ts"]
}
Output:
export interface Address {
city: string;
}
export interface Root {
id: number;
name: string;
email: string;
address: Address;
tags: string[];
}
| Option | Description |
|---|---|
-n, --name | Root interface name (default: Root) |
-o, --output | Write to file |
-t, --type | Use type instead of interface |
--optional | Make all properties optional |
--no-export | Don't add export keyword |
unknown[]Type an API response:
curl https://api.github.com/users/octocat | npx @lxgicstudios/json-to-ts -n GitHubUser
Generate types for project:
npx @lxgicstudios/json-to-ts sample-response.json -o src/types/api.ts -n ApiResponse
Built by LXGIC Studios