JSON to TypeScript Converter
Convert JSON objects and arrays to TypeScript types or interfaces with automatic nested type generation
Input
Output
Readme
Why convert JSON to TypeScript?
TypeScript uses static types to catch bugs at compile time rather than at runtime. When working with APIs, configuration files, or any external data source that returns JSON, you typically need to define types or interfaces that describe the shape of that data. Writing these definitions by hand is tedious and error-prone, especially for deeply nested objects or large arrays with varying structures. Automating the conversion saves time and reduces the risk of mismatches between your types and the actual data.
Tool description
This tool takes any valid JSON input — objects, arrays, or nested structures — and instantly generates corresponding TypeScript type aliases or interfaces. It automatically detects nested objects, creates separate named types for each, and handles arrays by inferring element types. You can switch between interface and type output modes depending on your project conventions.
Examples
Input JSON:
{
"id": 1,
"name": "Alice",
"email": "alice@example.com",
"address": {
"street": "123 Main St",
"city": "Springfield",
"zip": "62701"
},
"roles": ["admin", "editor"]
}Output (Interface mode):
interface RootObject {
id: number;
name: string;
email: string;
address: Address;
roles: string[];
}
interface Address {
street: string;
city: string;
zip: string;
}Output (Type mode):
type RootObject = {
id: number;
name: string;
email: string;
address: Address;
roles: string[];
};
type Address = {
street: string;
city: string;
zip: string;
};Features
- Choose between
interfaceortypealias output with a single dropdown - Automatic detection and extraction of nested object types
- Array element type inference, including arrays of objects
- Merges varying object shapes within arrays into a single unified type with optional properties
- Real-time conversion with syntax-highlighted JSON and TypeScript editors
Use cases
- Quickly defining TypeScript types for API response payloads during frontend development
- Generating type definitions from JSON config files or database exports
- Bootstrapping type-safe data models when starting a new TypeScript project
How it works
The tool parses valid JSON and recursively walks the structure. For each object it encounters, it creates a named interface or type alias with fields matching the object's keys. Nested objects produce additional types that are referenced by name. Arrays are analyzed to determine the element type — if all elements are objects, their shapes are merged into a single type where keys not present in every element become optional.
Tips
- Paste a representative sample of your JSON data. The more complete the sample, the more accurate the generated types will be.
- For arrays with mixed object shapes, include multiple objects so the tool can detect optional fields.
- Use Type mode if your project prefers type aliases for object shapes, or Interface mode if you follow the interface convention.