JSON to TypeScript Converter

Paste a JSON sample and the interfaces update as you go.

How it works

Every nested object gets its own named interface — named after its key, so address becomes interface Address — rather than being inlined, so the output reads the way you would actually write it by hand. An array of objects infers one shared shape across every element: a field present everywhere is required, a field missing from at least one element becomes optional, and a field whose type genuinely disagrees across elements (a string in one, a number in another) becomes a union. An array of primitives becomes Type[], and an empty array becomes unknown[] — there is nothing in an empty array to infer a type from. Interfaces are printed nested-first, root last, so every type is defined before the interface that references it.

Frequently asked questions

How does it decide a field is optional?

Only for an array of objects: a field counts as optional (field?: Type) when it is missing from at least one element of the array, and required when every element has it. A single object (not inside an array) has no other sample to compare against, so all of its fields come out required.

Two different keys generated the same interface name — what happens?

If two objects at differently-named keys would PascalCase to the identical interface name but have different shapes, a numeric suffix is appended to the second one (UserInfo, then UserInfo2) so neither definition is lost or silently overwritten. If they happen to have the exact same shape too, the second one just reuses the first interface instead of generating a duplicate.

Can this miss fields my real data actually has?

Yes — it infers structure from exactly the one JSON sample you paste in, nothing more. A field that simply never appears anywhere in that sample can't be inferred, and an array of objects only tells you which fields varied ACROSS the elements you gave it. Treat the output as a solid starting point to refine, not a guarantee that covers every shape your real data can take.