JSON to TypeScript

Paste an API response and get TypeScript interfaces for it. Objects in arrays are merged, so a field missing from some items becomes optional.

How it works

Each object becomes a named interface; nested objects get their own interface named after the key. Array items are merged into one type, and fields present in only some items are marked optional with ?.

Types are inferred from one sample, so a field that happens to be null becomes null. Adjust to string | null by hand where you know better.

Everything above runs in JavaScript inside this tab. Your data is not uploaded. Inputs are remembered in this browser only so they survive a reload; you can switch that off on the privacy page.

Questions

interface or type?

Either works for object shapes. Interfaces can be extended and merged; type aliases can express unions. Pick with the toggle.

Does it validate at runtime?

No. TypeScript types disappear at runtime. For runtime checks, validate with a JSON Schema.