JSON to TypeScript Converter
Generate TypeScript interfaces and types from JSON objects. Perfect for creating type-safe API responses, config files, and data models with automatic type inference and nested interface extraction.
Conversion Options
PascalCase name for root type
Recommended Settings
TypeScript Best Practices
- •Use interfaces for object shapes - they're more extensible than type aliases
- •Enable strictNullChecks in tsconfig for better type safety
- •Extract nested objects as separate interfaces for reusability
- •Use PascalCase for interface names and camelCase for properties
- •Prefer T[] syntax over Array<T> for consistency and readability
When to Use Type Aliases Instead
- •Union types: type Status = 'pending' | 'active' | 'complete'
- •Intersection types: type Combined = TypeA & TypeB
- •Primitive types: type ID = string | number
- •Mapped types: type Readonly<T> = { readonly [P in keyof T]: T[P] }
- •Complex compositions that interfaces can't express
Pro Tips
- •Generated types work with strict null checks when you enable 'Null values optional'
- •Use 'Preserve original keys' for API responses to match exact JSON structure
- •Arrays of objects automatically create separate interfaces for reusability
- •Empty arrays generate any[] - provide sample data for better type inference
Most Popular
Interface with export, preserved keys, semicolons, and 2-space indent
When to Use This Tool
Generate TypeScript interfaces for REST API responses and requests. Paste API JSON to create type-safe fetch calls, axios requests, and response handlers with full IntelliSense support.
Create types for Redux state, Zustand stores, or React Context. Generate interfaces from sample state objects to ensure type safety across your state management layer.
Type your config JSON files for build tools, package.json, tsconfig.json, or app settings. Import JSON with type assertions using generated interfaces for compile-time validation.
Convert database query results or document structures to TypeScript types. Works great for MongoDB documents, Firebase snapshots, or SQL query responses to add type safety to your data layer.
Generate types for mock data and test fixtures. Create interfaces from sample test data to ensure your tests use correctly typed mocks and fixtures.
Quick type generation from GraphQL query results or OpenAPI example responses. Use as starting point before codegen tools, or for one-off queries and responses.
How It Works
Paste JSON object into input field
Parse and validate JSON syntax
Analyze each property to infer TypeScript types
Detect nested objects and extract as separate interfaces
Handle arrays by analyzing element types (primitive, object, mixed)
Apply naming conventions (PascalCase for types, preserve or convert properties)
Generate interface or type declarations with selected modifiers
Format output with indentation, semicolons, and export statements
100% Private
Files never leave your device. All processing happens locally in your browser.
Lightning Fast
Powered by Pure JavaScript for optimal performance on modern browsers.
Secure
No data collection, no tracking, no sign-up required.
Frequently Asked Questions
What's the difference between interface and type?
Interfaces are better for object shapes and can be extended or merged. They're the TypeScript standard for defining data structures. Type aliases are more flexible and can represent unions, intersections, and primitives, but can't be reopened. Use interfaces for JSON objects (default) and types for complex compositions.
How are nested objects handled?
Nested objects are automatically extracted as separate interfaces with PascalCase names derived from the property key. For example, {user: {name: 'John'}} creates a User interface. This makes types reusable and keeps definitions clean.
What happens with arrays of different types?
Arrays with mixed types generate union types. For example, [1, 'text', true] becomes (number | string | boolean)[]. Arrays of objects create a separate interface: {items: [{id: 1}]} generates Item[] with an Item interface.
How are null values handled?
Null values in JSON become type 'null' by default. Enable 'Null values optional' to make these properties optional (?) instead. This works with strictNullChecks and makes the interface more usable since TypeScript doesn't allow assigning objects with null to most interfaces.
Can I convert arrays at the root level?
No, TypeScript interfaces/types must represent objects, not arrays. Wrap your array in an object first: {items: [...]}. This is a TypeScript language requirement - top-level exports must be object types.
What does 'Preserve original keys' do?
When enabled (default), property names match your JSON exactly (including snake_case). When disabled, property names convert to camelCase following TypeScript conventions. Use preserved keys for API responses, camelCase for internal app state.
Why use readonly modifiers?
Readonly properties prevent accidental mutations at compile time. Useful for configuration objects, API responses you shouldn't modify, or immutable data patterns. Note: readonly is compile-time only and doesn't prevent runtime changes.
Are my JSON files secure during conversion?
Yes, completely secure! All conversion happens entirely in your browser using client-side JavaScript. Your JSON data never leaves your computer or gets sent to any server. The tool works fully offline after the page loads.