How does JSON become a Dart model?
The converter infers Dart field types from the sample and creates a class for the root object plus separate classes for nested objects.
Generate Flutter-ready Dart models with fromJson and toJson.
Paste sample JSON and generate Dart / Flutter models locally in your browser.
Use an object or an array of objects for model inference.
Generated code will appear here.Generate Dart model classes from representative JSON for use in Flutter applications or other Dart projects. Inferred fields use Dart types, and nested objects become separate models that the root class can reference.
The available controls cover common hand-written Flutter model patterns: null-safe fields, final or mutable values, named parameters, required non-null parameters, and optional fromJson and toJson methods.
With null safety enabled, fields observed as nullable receive a question mark. Required constructor parameters are added only to fields that are neither missing nor nullable in the supplied samples.
The fromJson factory reads original JSON keys and constructs nested models. The toJson method converts nested models back to maps, so the generated class can support common Flutter data flows without a code-generation package.
Example JSON input:
[
{
"product_id": 12,
"details": { "display_name": "Notebook" },
"tags": ["paper", "office"]
},
{
"product_id": 13,
"details": null,
"tags": []
}
]Generated Dart / Flutter output:
class RootModel {
final int productId;
final RootModelDetails? details;
final List<String> tags;
RootModel({
required this.productId,
this.details,
required this.tags,
});
factory RootModel.fromJson(Map<String, dynamic> json) {
return RootModel(
productId: json["product_id"],
details: json["details"] == null ? null : RootModelDetails.fromJson(json["details"] as Map<String, dynamic>),
tags: json["tags"],
);
}
Map<String, dynamic> toJson() {
return {
"product_id": productId,
"details": details?.toJson(),
"tags": tags,
};
}
}
class RootModelDetails {
final String displayName;
RootModelDetails({
required this.displayName,
});
factory RootModelDetails.fromJson(Map<String, dynamic> json) {
return RootModelDetails(
displayName: json["display_name"],
);
}
Map<String, dynamic> toJson() {
return {
"display_name": displayName,
};
}
}The converter infers Dart field types from the sample and creates a class for the root object plus separate classes for nested objects.
Yes. The output is ordinary Dart code suitable for Flutter projects. It does not require Freezed, json_serializable, or another package.
When nullable fields are enabled, values observed as null receive nullable Dart types. Required parameters are limited to fields that are present and non-null in the sample set.
Yes. Each method can be enabled independently. fromJson reads the original JSON keys, and toJson writes those keys back into a map.
Yes. Nested objects and arrays of objects become named Dart models, with serialization calls added when fromJson or toJson is enabled.
Your JSON input, field names, root model name, and generated Dart / Flutter source stay in this browser. They are not sent to a backend, added to the URL, or saved in local storage or cookies.
Compare another language-specific converter that uses the same local JSON inference engine.