How to use the JSON to TypeScript converter
- Paste a representative sample into the JSON box, such as an API response.
- Enter a Root type name, for example
UserorOrder. - Under Declare as, choose interface or type.
- Leave Export declarations ticked to add
exportso the types can be imported from other files. - Copy the TypeScript output or download it as
types.ts.
What it does and when to use it
Writing types by hand for a large API response is slow and easy to get wrong. This converter reads real data and writes the matching TypeScript declarations: numbers, strings, booleans, arrays, nested objects and null. Use it when you start working with a new API, when you add types to an older JavaScript project, or when you want a first draft of types to refine.
Each nested object becomes its own named declaration, so address becomes Address. Keys that are not valid identifiers, such as content-type, are quoted. For an array at the root, the root name becomes an array type and the item type is named in the singular, so Users gives User[].
If the JSON will not parse, check it with the JSON validator first. To make the sample readable before converting, use the JSON formatter. Writing in Go instead? The JSON to Go converter builds structs the same way.
How it works
The JSON is parsed in your browser, then walked from the root. For each value the converter records its type. For arrays of objects, it merges the fields of every element: if a field is missing from any element it becomes optional, and if it has different types in different elements the types are joined into a union. Arrays of plain values become string[], number[] and so on. Finally it prints the declarations, root first, with two-space indentation.
Worked examples
All TypeScript below is the converter’s own output.
A single object with nesting. The JSON {"id":1,"name":"Asha","tags":["a"],"address":{"city":"Pune"},"manager":null} with root name User gives:
export interface User {
id: number;
name: string;
tags: string[];
address: Address;
manager: null;
}
export interface Address {
city: string;
}
manager is typed null because that is the only value the sample shows.
An array with a missing field. [{"id":1,"email":"a@x.io"},{"id":2}] with root name Users gives export type Users = User[]; and an interface User with id: number; and email?: string;. The second item has no email, so the field is optional.
Limits and tips
- Your sample sets the limits. A field that never appears in the sample will not appear in the types. Paste several varied items if you can.
- Dates stay strings. JSON has no date type, so
"2026-10-03"becomesstring. - Enums are not guessed. A
statusfield with values like “active” is typedstring; narrow it to a union by hand if you want stricter types. - Names may need tidying. Generated names come from keys, so rename them to fit your project.
Frequently asked questions
Should I use interface or type?
How does it decide which fields are optional?
Why is a field typed as null?
Does it validate data at runtime?
Is my JSON sent anywhere?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.