JSON to TypeScript

Paste a JSON sample and get matching TypeScript interfaces — nested objects, arrays, optional properties and unions included.

How the types are inferred

Each value gets the matching TypeScript type: string, number, boolean or null. Nested objects become their own named interfaces (named after the property, with arrays singularised: items becomes Item). For arrays, all elements are merged into one type: a property that is missing from some elements becomes optional (b?: string), and values of different types become a union (string | number). Empty arrays become unknown[].

A single JSON sample can only show what that sample contains, so check the result against your API documentation: a field that is always null in your sample may hold another type in real data. Everything is worked out in your browser and your JSON is never uploaded.

Running into a technical issue or something that doesn't work right on this page? Please let us know straight away via our Contact page — that's how we find out what's broken and get it fixed.