Advertisement

JSON to Dart Class

Convert JSON into Dart model classes for Flutter. Final fields, named constructors, required and nullable modifiers are inferred from your data.

JSON input

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

Your Dart class code will appear here.
Advertisement

Null safe models for Flutter

Dart's null safety means every field must declare whether it can be null. The generator answers that from your sample: consistently present fields become required, the rest become nullable, and nested objects become nested classes.

From REST API to widgets

Flutter apps live on JSON APIs. Generating the model layer from a real response removes the most tedious part of wiring up a new endpoint, leaving you to focus on the UI.

JSON to Dart Class FAQs

How do I parse JSON into these classes?
The standard approach is a factory constructor using jsonDecode, or code generation with json_serializable. The field types here match what both approaches expect.
What do required and ? mean?
Fields always present become required named parameters, while uncertain fields become nullable (String?) without required, mirroring Dart's null safety.
How are nested objects handled?
Each nested object becomes its own class with its own constructor, so the model tree matches the JSON tree exactly.
How are arrays typed?
JSON arrays become List<T> with T inferred from the elements, which is what Flutter code expects when rendering lists of API items.
Is this compatible with json_serializable?
Yes. The class shapes follow the conventions that package expects, so adding the annotations and running build_runner works directly.
Advertisement