Plain object
- Input
- {"id":1,"name":"Ana","active":true}
- Expected output
- export interface Root { id: number; name: string; active: boolean; }
Text, number and boolean.
convert json to typescript interface
Paste the JSON, keep TypeScript selected and copy the interface. With more than one sample, the tool finds which fields are optional and which accept null.
Text, number and boolean.
The second item has no email: it becomes email?. The root array uses type.
Two documents: one with text and one with null.
A number in one document and text in the other: a union.
user-name needs quotes, class does not.
items generates the Item interface, singular.
A field is optional when it is missing from at least one of the objects observed at that position, whether in different documents or in different items of the same array. If every object in a 50-item array has the key phone, it is required; if one does not, it becomes phone?: string. A null value does not make the field optional: it makes it nullable (string | null). The two concepts are different in APIs and in languages, so the tool keeps them apart. The All fields optional switch marks every field optional, which is useful for PATCH bodies and partial responses.
For data objects both work. An interface allows extends and declaration merging under the same name; a type allows unions and tuples in the same syntax. The tool generates interface by default and switches to type under Options. Unions and arrays at the root always use type, because an interface only describes objects.
As a string. JSON has no date type, and JSON.parse does not create Date objects. RFC 3339 dates such as 2026-03-14T09:30:00Z are recognized and produce the date-time format in other targets, but in TypeScript the field stays a string until you convert it with new Date(value).
The readonly modifier prevents reassigning the property once the object exists, and on arrays it produces readonly T[], which has no push or splice. It is only a compiler check: nothing changes at runtime. Turn on Immutable under Options to generate it.
unknown is the safe type for an unknown value: the compiler requires a check before use. any turns checking off. The tool uses unknown for plain null, empty arrays and empty objects.
export type Root = RootItem[];
export interface RootItem {
id: number;
number: string;
status: string;
createdAt: string;
total: number;
customer: Customer;
items: Item[];
tags: string[];
shipping: Shipping;
billing?: Shipping;
couponCode?: string;
}
export interface Customer {
id: string;
name: string;
email: string;
phone: string | null;
}
export interface Item {
sku: string;
name: string;
qty: number;
price: number;
}
export interface Shipping {
street: string;
city: string;
zip: string;
}
A string with a few repeated values, in at least 8 samples, becomes an enum.
Date-time, date, UUID, email, URL and IPv4.
Objects with the same fields become one type.
Keys that look like ids or dates become a map, and an empty object becomes a map of unknown values.
A fixed-length array with different types per position, like ["a", 1].
Avoids int when the samples happen to contain only integers.
Rejects trailing commas, comments, single quotes and similar.
Language style: camelCase, snake_case or PascalCase, annotated with the original key. Dataclass and TypedDict always keep the keys.
Go, C#, Java, Swift and Pydantic. In other languages the field stays a string.
readonly in TypeScript, frozen in Python, init in C# classes and let in Swift.
The JSON is processed in your browser. Nothing you paste or open is sent to servers.