JSON to TypeScript Interface Generator
Convert JSON to TypeScript interfaces and type aliases instantly. Supports nested objects, arrays, null types, and optional fields with configurable output options.
Features
đˇ TypeScript Types
- Interface and type alias support
- Nested object interfaces
- Array type inference
- Null-aware optional fields
âī¸ Configurable Output
- Toggle interface vs type
- Export declarations
- Readonly modifiers
- Nested type generation
đ¯ Type Accuracy
- string, number, boolean inference
- unknown | null for null values
- Type[] for arrays
- unknown[] for empty arrays
TypeScript Guide
Interface vs Type
TypeScript interfaces and type aliases are both used to describe object shapes. Interfaces are extensible with declaration merging; type aliases support unions and intersections.
// Interface (extensible)
export interface User {
id: number;
name: string;
active: boolean;
}
// Type alias (flexible)
export type User = {
id: number;
name: string;
active: boolean;
};
Getting the most out of generated TypeScript types
Generated types are a starting point, not the final word. A single sample only shows the shape of one response, so treat the output as a draft that you tighten once you know which fields are optional, which can be null and which strings are really enums.
Tips and common pitfalls
- Paste the largest, most complete response you have. Fields that are missing from the sample cannot appear in the generated types.
- Replace broad
stringfields with union types where the API documents a fixed set of values, for example"draft" | "published". - Types disappear at runtime. If the data comes from outside your code, validate it as well, for example with a Zod schema generated by our JSON to Zod tool.
- Keep generated types in their own file so you can regenerate them without losing hand-written code.
More questions
Should dates be typed as Date or string?
JSON has no date type, so a date arrives as a string. Type it as string and convert it with new Date() where you need it; typing it as Date would be a lie the compiler cannot catch.
How do I type an API response that wraps data in an envelope?
Generate types from the full response, then use indexed access types such as ApiResponse["data"] to refer to the inner payload instead of duplicating it.