Paste a JSON sample and read the interfaces. Nested objects get their own names.
1
1
TypeScript describes the shape of a value with types that are erased when the program is compiled. An interface names an object: each field has a name and a type such as string, number, or boolean.
This page reads one JSON sample and writes interfaces. A nested object becomes its own interface. An array of objects is merged: a field missing from some elements is optional.
{"name":"Ada","score":10}export interface Root {
name: string;
score: number;
}[{"id":1},{"id":2,"name":"Ada"}]export interface Root {
id: number;
name?: string;
}
export type RootList = Root[];Treat the interfaces as every value the API can send
Check a field that is missing from this sample before dropping the question mark
An empty array becomes unknown[], because the sample does not show the element type. An empty object becomes an interface with no fields.
JSON does not allow comments or trailing commas. A file that a bundler accepts may still be rejected here.
Field names that are not identifiers are quoted. A nested interface is named from the key: user_id becomes UserId. A collision gets a numeric suffix.
The share link stores the JSON and the root name, not the generated interfaces. Opening the link runs the conversion again. Anyone who has the link can read the JSON.
Microsoft announced TypeScript on 1 October 2012. Anders Hejlsberg, who had led the C# design, presented it. Interfaces exist only for the type checker: the compiler deletes them.
Douglas Crockford specified JSON in RFC 4627 in July 2006. The current definition is RFC 8259, published in December 2017. A JSON number has no integer type, so every finite number on this page is number.