JSON to TypeScript
Generate TypeScript types
What Is This Tool?
The JSON to TypeScript tool generates TypeScript interface declarations from a sample JSON value. Paste in a representative JSON object or array and it infers property types, nests interfaces for objects found within, and unions the element types of arrays that mix scalar types. It's a fast way to bootstrap types for an API response without hand-writing them. Everything runs locally in your browser.
How to Use
Paste a representative sample of your JSON data.
Optionally set a name for the root interface (defaults to Root).
Click Generate to produce TypeScript interfaces.
Features
- Infers nested interfaces from nested objects, named after their property
- Infers array element types, including unions for mixed-type arrays
- Marks
null/missing-type values asunknownwith an explanatory comment - Custom root interface name
- Copy or download the generated
.tsfile - 100% client-side — nothing leaves your browser
Examples
JSON:
{
"name": "Ada Lovelace",
"age": 36,
"tags": ["mathematician", "writer"],
"address": { "city": "London", "zip": "W1" }
}
Generated TypeScript:
interface RootAddress {
city: string;
zip: string;
}
interface Root {
name: string;
age: number;
tags: string[];
address: RootAddress;
}
Common Use Cases
- Bootstrapping TypeScript types from an API response sample
- Quickly documenting the shape of a JSON config file
- Turning a saved fixture into typed test data
- Speeding up onboarding to an unfamiliar JSON payload
Frequently Asked Questions
How are nested object types named?
Nested interfaces are named by combining the root interface name with the capitalized property name, for example an address property under Root becomes RootAddress. An object found inside an array is named after the array's property, for example an item in items[] becomes RootItem.
What happens with arrays of mixed types?
If an array's elements aren't all the same scalar type, the tool generates a union type, for example (string | number)[].
What does unknown mean in the output?
When a value is null or otherwise gives no usable type information from the sample, the property is typed as unknown with a comment noting the sample provided no type information. Provide a non-null example value for a more precise type.
Does it deduplicate identical object shapes?
No. As a simplification, each object encountered gets its own named interface even if an identical shape already exists elsewhere in the output. You may see repeated interface bodies for structurally identical objects.
Can I use my own root interface name?
Yes, enter any valid TypeScript identifier in the Root Interface Name field before generating; nested interface names are derived from it.
Is my JSON data uploaded anywhere?
No. Type inference happens entirely in your browser using JavaScript. Nothing is sent to a server.
Can I download the result as a file?
Yes, click Download to save the generated interfaces as a .ts file.