JSON to TypeScript Types
Paste JSON and get TypeScript interfaces straight away. Nested objects get their own interface, arrays are merged into one type, and fields missing from some items become optional. Nothing is uploaded.
How to use JSON to TypeScript Converter on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for speed, privacy and clean results.
What you can do with JSON to TypeScript Converter
Everything this tool is good for.
About JSON to TypeScript Converter on KickSolve
What it does, how it works and how to get the best results.
How types are inferred
The tool reads your JSON and describes each value: strings, numbers, booleans and null, nested objects as their own interfaces, and arrays as lists of the merged item type. It is inferred from the sample, so the more representative your sample, the better the types.
Optional fields and unions
When array items have different keys, a key missing from some items is marked optional with a question mark. When the same key holds different types, the type becomes a union such as string | number. A null value is typed as null, so add it to a union yourself if the real field can also hold a value.
Interface or type
Interfaces are the usual choice for object shapes and can be extended. Type aliases work the same for these shapes and are handy if your project prefers them. The Export setting adds the export keyword to every declaration.
Limits to keep in mind
All numbers become number, dates arrive as strings, and an empty array becomes unknown[] because there is nothing to infer from. Review the output and tighten the types by hand where you know more than the sample shows.
Related tools
Format and validate your JSON first with the JSON Formatter, explore it with the JSONPath Tester, or turn it into a table with JSON to CSV.
Worked example: JSON to TypeScript
Nested objects and an array with a missing field.
Input:
{"id": 1, "name": "Ana", "address": {"city": "Lahore"},
"orders": [{"sku": "A1", "qty": 2}, {"sku": "B2"}]}
Output:
export interface Order {
sku: string;
qty?: number;
}
export interface Address {
city: string;
}
export interface Root {
id: number;
name: string;
address: Address;
orders: Order[];
}The second order has no qty, so qty is optional. Each nested object became its own interface.
How JSON maps to TypeScript
The type chosen for each kind of value.
| JSON value | TypeScript type |
|---|---|
"text" | string |
12 or 1.5 | number |
true | boolean |
null | null |
| Object | Its own interface, or Record<string, unknown> if empty |
| Array of objects | A merged interface array, with optional fields where items differ |
| Mixed types for one key | A union, such as string | number |
| Empty array | unknown[] |
Frequently asked questions
Quick answers.
How do I convert JSON to TypeScript?
Paste your JSON, set the root name and options, and copy the generated interfaces. They update as you type.
Should I use interface or type?
Either works for these shapes. Interfaces are the common choice for objects, and type aliases are fine if your project prefers them. Use the Declaration setting to switch.
How are optional fields decided?
A field that is missing from at least one item in an array is marked optional with a question mark.
What happens when a field has different types?
The type becomes a union of the types that were seen, such as string | number.
Why is my array typed as unknown[]?
An empty array gives the tool nothing to infer from. Replace unknown with the real item type.
Are dates and integers detected?
No. Dates arrive in JSON as strings and every number is typed as number. Adjust these by hand if you need more precise types.
Can I generate types from several API responses?
Put several sample items into one array so the tool can merge them and find the optional fields.
Is my JSON uploaded?
No. The types are generated in your browser and nothing is sent to a server.
More free tools from KickSolve
Related free tools. Each one runs in your browser too.