๐Ÿ”ท

JSON to TypeScript Types โ€” Generate TS Type Aliases from JSON

Auto-generate TypeScript interfaces from any JSON โ€” nested objects ยท optional fields ยท readonly ยท export ยท 100% Free

JSON INPUT
โš™ OPTIONS
TYPESCRIPT OUTPUT
๐Ÿ”ท
TypeScript interfaces appear here
Paste JSON on the left ยท click a Sample ยท or drag & drop a .json file
export interface User {
  id: number;
  name: string;
  active: boolean;
  address: Address;
}
Ctrl+Enter GenerateCtrl+Shift+C Copy outputCtrl+L ClearCtrl+S Download .tsP Pin
๐Ÿ’ก

TypeScript type aliases offer more flexibility than interfaces โ€” supporting union types, intersection types, mapped types and conditional types. This generator creates type aliases from your JSON, with options to output type instead of interface syntax. Useful when you need to compose types or work in codebases that prefer type over interface.

๐Ÿ“Œ JSON to TypeScript Type Aliases
{"status":"active","priority":1,"tags":["urgent","billing"]}
type Status = string; type Tags = string[]; type Root = { status: Status; priority: number; tags: Tags; };

What is JSON to TypeScript Interface Generation?

This tool analyses the structure of your JSON data and automatically generates TypeScript interface or type declarations โ€” saving you the time of writing them manually. It infers string, number, boolean, null, nested object interfaces, and typed arrays. When your JSON is an array of objects, optional fields are detected automatically.

How Nested Objects Are Handled

Every nested JSON object generates its own named TypeScript interface. For example, if your JSON has "address": { "city": "Ahmedabad" }, the tool generates a separate Address interface and references it as address: Address in the parent interface โ€” matching real-world TypeScript project structure.

Frequently Asked Questions

When should I use TypeScript type alias vs interface?

Use type for: union types (type Status = "active" | "inactive"), intersection types (type Admin = User & AdminRights), primitive type aliases (type ID = string), function types. Use interface for: object shapes, class implementations, extensible models (interface B extends A), declaration merging. For JSON API types, either works โ€” pick one style for consistency.

Can TypeScript type aliases be extended like interfaces?

Not with extends keyword, but you can use intersection: type Extended = Base & { newField: string }. Interfaces support: interface Extended extends Base { newField: string }. Both achieve similar results. Interfaces support declaration merging across files โ€” type aliases don't. This matters when augmenting third-party library types.

How do I create union types from JSON enum-like values?

If your JSON has a field like "status": "active" where status can be "active", "inactive" or "pending", generate: type Status = "active" | "inactive" | "pending". The auto-generator sees "active" (string) and generates type: string. Manually refine to union type for better type safety โ€” IDEs will autocomplete the exact values.

What are mapped types and when should I generate them from JSON?

Mapped types transform existing types: Partial<T> makes all fields optional. Required<T> makes all required. Readonly<T> makes all readonly. Pick<T, "field1"|"field2"> selects specific fields. Instead of generating these from JSON, generate the base interface from JSON, then apply mapped types: type UpdateInput = Partial<User>.