Free Online JSON to Code Generator
Turn any JSON document into TypeScript interfaces, a JSDoc typedef, Python dataclasses or TypedDicts, or Go structs with json tags. Every item of an array is read rather than only the first, so a key that is missing from some items becomes optional instead of wrongly required, and repeated shapes are reused.
Enjoying WizTools123? Help keep our server infrastructure 100% free and open for everyone.
How to Generate Types From JSON
A few steps, and nothing is uploaded.
What to Know About Generated Types
Where a single example lies, and what the generator does about it.
closed_on becomes ClosedOn with a json:"closed_on" tag to map it back. Known initialisms are capitalised the way the language expects, so id becomes ID and url becomes URL, which is what a linter will otherwise ask you to do.
Key Features & Capabilities
What this tool does, and what it deliberately does not.
About Generating Code From JSON
Writing types by hand from an API response is dull, and being dull is not the problem with it. The problem is that it is quietly error prone in one specific way: you look at one example. The example has fifteen fields, you write fifteen fields, and three months later something fails because one of those fields is absent whenever the order has not shipped yet. Your type said it was always there, the compiler believed you, and nothing checked.
That is why the interesting part of generating code from JSON is not the printing, it is the reading. Given an array of records, the right answer comes from merging all of them: a field present in every item is required, a field present in some is optional, and a field that is a string in one item and a number in another is both. Most generators take the first element and stop, which produces types that are confidently wrong in exactly the way that is hard to debug.
Null is the other subtle one. A null in the sample tells you the field can be empty and tells you nothing at all about what it holds when it is not empty. Treating null as a type produces something useless; treating the field as nullable keeps the one fact you actually learned. And when every example of a field is null, the honest output is unknown, because there is nothing there to work from.
The rest is respecting each language rather than printing the same thing four ways. Go wants exported names with tags mapping back to the original keys, and it wants ID rather than Id. Python dataclasses require fields with defaults to come last, so optional fields have to move, and you should be told that they did. TypedDict does not have that rule and keeps the document order. These are small things, and getting them wrong is what makes generated code feel like something you have to fix before you can use it.
Frequently Asked Questions
Languages, optional keys, nulls and naming.