devShakib

Loading devShakib…

JSON to Model

Turn a JSON sample into typed Dart classes or TypeScript interfaces, nested objects included.

Generating a class from a JSON sample is really type inference from one example, and the inference is only as good as the example. A field that happens to be null in your sample has no discoverable type; a number that happens to be whole looks like an int until the day it arrives as 1.5; an empty array says nothing about what belongs in it.

Nested objects are where hand-writing this stops being worth it, because each level needs its own type and its own parsing, and the tedium is exactly the sort that produces typos. Treat the output as a first draft: check nullability against your API's contract rather than against the one response you happened to paste.