JSON to TypeScript
Convert JSON data to TypeScript interfaces or type aliases instantly. Generate strongly-typed definitions with customizable options for your TypeScript projects.
Generator Options
JSON to TypeScript Type Mapping
JSON string
→ string
JSON number
→ number
JSON boolean
→ boolean
JSON null
→ null
Why use JSON to TypeScript Generator?
Manually creating TypeScript interfaces from JSON is tedious and error-prone. This tool automatically generates accurate type definitions, handling nested objects, arrays, and mixed types. Perfect for working with APIs, configuration files, or any JSON data in TypeScript projects.
Frequently Asked Questions
What's the difference between interface and type?
Both can define object shapes, but interfaces are extendable (can be extended or implemented), while type aliases are better for unions, intersections, and more complex types. Use interface for API contracts and type for utility types.
How are arrays handled?
Arrays are detected and typed based on their contents. If all elements have the same type, you get 'Type[]'. For mixed types, you get a union like '(string | number)[]'. Empty arrays become 'unknown[]'.
What about nested objects?
By default, nested objects become separate interfaces. Enable 'Inline Nested' to embed them directly in the parent type. Separate interfaces are better for reusability, while inline is cleaner for one-off structures.
How do optional properties work?
When 'Optional Properties' is enabled, all properties get a '?' suffix (e.g., 'name?: string'). This is useful when generating types for data that may have missing fields.