Advertisement

JSON to TypeScript Type

Convert JSON into idiomatic TypeScript type aliases. Nested objects become named types, arrays get element types, and missing keys become optional.

JSON input

Paste JSON, optionally name the root type, then generate.

Your TypeScript type code will appear here.
Advertisement

Type aliases from real data

The generator inspects your JSON and builds a type alias for the root plus one for every nested object. Arrays are typed by their elements, primitives map to string, number, and boolean, and inconsistent keys across array items become optional properties.

Why generate instead of hand writing

Hand writing types for a large API response is slow and error prone. Generating from a real payload captures every field, including ones buried three levels deep, and you can paste the result straight into a .ts file.

JSON to TS Type FAQs

What is the difference between this and the interface version?
Both describe the same shape, but this page emits type aliases (type X = {...}) while the interface page emits interfaces. Type aliases compose better with unions and mapped types.
When should I use a type alias instead of an interface?
Use type aliases when you plan to combine shapes with unions or intersections, for example type Result = Success | Failure. Interfaces are better for class-like extension hierarchies.
How are arrays of objects typed?
An array of objects becomes a named type plus an array of it, like Project[], with the element type declared once above the root type.
What happens with null values?
Fields whose value is null are marked optional, since a null sample usually means the field can be absent. Review them before committing to your codebase.
Does the output work with strict mode?
Yes. The generated types use explicit optionality and avoid implicit any, so they compile cleanly under strict TypeScript settings.
Advertisement