Binatomy
TypeScript Generator

JSON to TypeScript

Paste JSON and instantly generate TypeScript interfaces, with recursive inference of nested objects, arrays and optional types
FAQ

Frequently Asked Questions

Everything you need to know about generating TypeScript interfaces

How are types inferred from JSON?

The tool recursively analyzes your JSON: strings become string, numbers become number, booleans become boolean. Each nested object generates its own interface with a PascalCase name derived from the key, while arrays produce [] types by inferring the element type. Null values are treated as optional properties.

How are arrays and mixed types handled?

For arrays, the tool examines all elements and builds a union type when it finds different types (for example (string | number)[]). An empty array becomes any[]. If the elements are objects, a reusable interface with a singular name is generated. All computation happens in your browser, your JSON never leaves your device.

Can I change the name of the main interface?

Yes, use the "Root interface name" field to set the name of the top-level interface. The text is automatically converted to valid TypeScript PascalCase. Nested interfaces are automatically named from their respective keys, with numeric suffixes added in case of collisions to guarantee unique names.

How are the arrays in the JSON typed?

Every element of the array is examined and the types found form a union. When the elements all share one shape the result is an array of a single interface, otherwise a union between the types appears.

What happens to null values in the JSON?

A null in the source JSON produces a property marked optional with a question mark and typed null, because the sample on its own cannot say what the real type of that field is.