JSON to TypeScript

Paste a JSON payload and get a TypeScript interface, with optional fields worked out from the records that disagree.

json
TypeScriptts
The result appears here
Made something you like?Blocks that render this data

Questions

How are optional fields decided?+

From an array of objects. A key present in some elements and missing from others comes out optional; a key present in all of them does not. One lone object cannot tell you that, so everything in it is required.

Why are nested objects inline rather than separate interfaces?+

Because the shape stays readable and you can see the whole payload at once. Pull a nested object out into its own interface when you need to name it, which is a decision about your code rather than about the sample.

What happens to null?+

A field that is null in every sample is typed null, since one sample cannot say what else it holds. A field that is null in some records and a value in others becomes that type unioned with null.

Related tools

The tools are free. So is most of the library.

1935 blocks and 989 pieces for shadcn/ui and Tailwind, built on the same tokens these tools write. Install one with a command and the code is yours.

No signup for the tools. MIT for free blocks, commercial licence for Pro.

Markdown version