JSON to TypeScript
Generate TypeScript interfaces from a JSON sample
0 chars
—
What this can and cannot infer
- One sample is evidence, not a schema. A member absent from some records becomes optional (x?:); a member that is present but null becomes nullable (T | null). Those are different facts, so they are kept apart.
- Objects in the same position are merged across every array element, not read from the first one — so an array where two records carry an extra field yields one interface with an optional member.
- No literal or enum types: a sample cannot tell a fixed set of strings from a string. No tuples either — a mixed array becomes an array of a union.
- No date detection and no integer/float split: JSON has one number type and so does TypeScript.
- A structure that references itself produces one interface per level of the sample rather than a recursive type. Collapse those by hand.
- Nothing here is fetched or sent: the sample is parsed in this tab with JSON.parse.