JSON to TypeScript
Paste a JSON response to get TypeScript interfaces for it — nested objects, arrays, and optional keys included.
JSON
Processed locally. Your JSON never leaves your browser.
TypeScript
Paste some JSON to generate TypeScript interfaces.
Common questions
How are nested objects handled?
Each nested object becomes its own named interface, referenced from its parent — so a "user" key produces `user: User;` plus a separate `interface User`. Names come from the key itself, and an array key is singularized ("categories" gives you a `Category` interface).
What happens with an array of objects that have different keys?
The objects are merged into one interface, and any key that is missing from at least one of them is marked optional with `?`. That way a list where only some items have a "nickname" produces `nickname?: string` instead of two competing interfaces.
Why is an empty array typed as unknown[] instead of any[]?
An empty array carries no information about what it holds, and `unknown[]` says exactly that while keeping type checking switched on. `any[]` would silently disable checking everywhere the value is used. If the same field has real values elsewhere in the JSON, those are used instead.
How are null values typed?
A value that is only ever `null` is typed as `null`, because that is genuinely all the JSON shows. When a field is null in one array item and a string in another, the two are combined into `string | null`.
What if my JSON is invalid?
You get the exact error with its line and column — the same JSON validation used by this site's JSON Formatter, so trailing commas, unquoted keys, and missing values are all reported precisely rather than as a generic failure.
Is my JSON sent anywhere?
No. The conversion runs entirely in your browser; nothing you paste is uploaded to a server.