JSON to TypeScript Converter
Paste a JSON response or sample object and get clean TypeScript interfaces in return — nested objects become their own types, arrays are merged, and fields that are missing from some items are marked optional.
TypeScript
export interface User {
id: number;
name: string;
email: string;
isActive: boolean;
roles: string[];
address: Address;
orders: Order[];
lastLogin: null;
}
export interface Order {
id: string;
total: number;
items: number;
coupon?: string;
}
export interface Address {
city: string;
country: string;
}Stop writing interfaces by hand
Every time you integrate an API, you need types that describe its responses. Writing them manually is slow and easy to get wrong — a missed optional field or a misspelled key only shows up as a bug later. This converter reads a sample of real JSON and generates TypeScript interfaces for it instantly, so you get autocomplete and type checking in seconds.
How to use the converter
- Paste a JSON response, config file or sample object into the left panel.
- Set the name of the root type, such as User or ApiResponse.
- Choose interface or type alias, and whether to export them or make them readonly.
- Copy the generated TypeScript from the right panel into your project.
If the JSON has a syntax error, the message tells you where to look.
How types are inferred
- Primitives — strings, numbers and booleans map directly;
nullbecomes thenulltype. - Nested objects become their own named interfaces, named after their key: an
addressfield produces anAddressinterface. - Arrays are typed from all of their elements. Arrays of objects are merged into one interface named in the singular —
ordersgivesOrder[]. - Optional fields — if a key is missing from some objects in an array, it’s marked with
?. - Mixed types become unions, such as
string | nullor(number | string)[]. - Identical shapes are reused, so two fields with the same structure share one interface.
- Unusual keys such as
"first-name"are quoted so the output is always valid TypeScript.
Getting the best results
Types are only as good as the sample. Use a response that includes every field you care about, with real values rather than null, and include several items in arrays so optional fields can be detected. Empty arrays become unknown[] because there’s nothing to infer from. For date strings, IDs or enums, you may want to refine the generated types by hand — for example, replacing string with a union of allowed values.
interface or type?
Both describe object shapes equally well. Interfaces can be extended and merged across declarations and often give clearer error messages; type aliases can also describe unions, tuples and mapped types. Many teams use interfaces for API data and types for everything else — follow your codebase’s existing convention.
Everything runs in your browser, so private API data never leaves your device. Tidy up messy JSON first with the JSON Formatter, turn a curl command into typed fetch code with the cURL Converter, and inspect auth tokens with the JWT Decoder.
Frequently asked questions
How are optional properties detected?
When an array contains several objects, the converter merges them. A property that's missing from any of the objects is marked optional with a question mark, because the sample shows it isn't always present.
What happens with null values?
A property that's null in the sample gets the type null. If it's null in some items and a string in others, it becomes string | null. Provide a sample with real values for the most accurate types.
Should I use interface or type?
For object shapes they're mostly interchangeable. Interfaces can be extended and merged, and give slightly clearer error messages; type aliases can express unions and other advanced types. Pick whichever your codebase already uses.
Are identical nested objects combined?
Yes. If two properties have exactly the same shape — for example billing and shipping addresses — they share one interface instead of creating duplicates.
Is my JSON sent anywhere?
No. The conversion happens entirely in your browser, so API responses containing private data never leave your device.