How do I generate TypeScript interfaces from JSON?
Paste your JSON data and instantly get TypeScript interfaces with correctly inferred types for strings, numbers, booleans, arrays, nested objects, and nullable fields. Customize the root interface name and toggle between interface and type alias output. Everything runs in your browser — your data never leaves your device.
{"id":1,"name":"Alice","email":"a@b.com","active":true}interface Root {
id: number;
name: string;
email: string;
active: boolean;
}JSON to TypeScript
Generate TypeScript interfaces or type aliases from JSON data. Handles nested objects, arrays, nulls, and mixed types.
About JSON to TypeScript
- Interfaces vs Types — interfaces are extendable and commonly used for object shapes; type aliases support unions and intersections.
- Nested objects— by default, each nested object gets its own named type. Enable "Inline nested" to embed them directly.
- Arrays — element types are inferred from all items. Mixed-type arrays become union types (e.g.,
(string | number)[]). - Root arrays — if your JSON is an array of objects, all objects are merged to produce a complete type.
- Null values — inferred as
null. Enable "Optional props" to mark all properties with?. - Everything runs in your browser — no data is sent over the network.
Tips & Best Practices
Prefer interfaces over types for object shapes
TypeScript interfaces support declaration merging, better error messages, and faster type checking. Use 'interface' for object shapes (API responses, props, configs) and 'type' for unions, intersections, and mapped types. In large codebases, this distinction improves IDE performance and compiler speed.
Inferred types from JSON samples miss nullable fields
If your JSON sample has all fields populated, the generated TypeScript types won't include null or undefined. Real API responses often have optional fields. After generating types, review each field: should it be required or optional (?)? Can it be null? The sample data is just one snapshot — your types should cover all valid states.
Use utility types to derive related types
Generate the base type from JSON, then use TypeScript utilities: Partial<User> for patch endpoints, Pick<User, 'id' | 'name'> for list views, Omit<User, 'password'> for public responses. This avoids duplicating type definitions and ensures changes propagate automatically.
Runtime validation must match your TypeScript types
TypeScript types are erased at runtime — they don't validate actual API data. An API returning {age: "thirty"} won't trigger a type error at runtime even if you typed age as number. Use Zod, io-ts, or valibot to validate data at system boundaries (API calls, form inputs, file reads).
Frequently Asked Questions
How do I generate TypeScript types from JSON?
Should I use interface or type for TypeScript types?
How does the JSON to TypeScript converter handle nested objects and arrays?
Related Convert Tools
OpenAPI to TypeScript
Convert OpenAPI 3.x and Swagger 2.0 specs to TypeScript interfaces and types with $ref resolution, allOf/oneOf/anyOf, enums, and API operation types
JSON to Zod Converter
Convert JSON or JSON Schema to Zod validation schemas with $ref resolution, allOf/oneOf/anyOf, enum, format constraints, and required/optional fields
GraphQL to TypeScript
Convert GraphQL SDL schemas to TypeScript interfaces, types, enums, unions, and operations
TypeScript to JavaScript
Convert TypeScript to JavaScript — strip types, interfaces, enums, generics, and access modifiers to get clean JS output