JSON to Dart Class
Paste JSON and get Dart model classes with fromJson and toJson, or freezed output for Flutter. Null safety supported. Private.
Paste JSON on the left. Add a second sample to find optional fields.
JSON input
Stays in your browserDart code
Shortcuts: Ctrl+Enter run · Ctrl+Shift+C copy result · / search (use ⌘ on Mac)
Next steps
Need the same types in another language? JSON to TypeScript, JSON to Go Struct, JSON to Rust Struct, JSON to C# Class, JSON to Java POJO, JSON to Python Dataclass. Or validate a document against a JSON Schema.
Free Online JSON to Dart Class Generator
Generate Flutter-ready Dart model classes from a JSON sample, with serialization methods included. It gives developers a quick browser-based way to solve a focused json to dart class task before moving the result into a project.
How to generate Dart code from JSON
Paste a JSON object or an array of objects into the input box and press Generate. Plain mode writes final fields with fromJson and toJson. Freezed mode writes a @freezed class with json_serializable parts and a fromJson factory.
One input, every language
Your JSON stays in the box when you switch the language tabs, and the code is generated again at once. Each language also has its own page, so you can bookmark the one you use.
How types are worked out
- Whole numbers and numbers with decimals are told apart.
- Add more samples with Add sample: a key missing from some samples becomes optional, and null makes a type nullable.
- Arrays of objects are merged into one type, and nested objects become their own types named after the key.
- Keys that are not valid names in the language (such as first-name or 2fa) are renamed and mapped back, never rejected.
Worked example
The sample JSON in the box above, generated with the default options:
{
"id": 1,
"name": "Ada",
"email": null,
"tags": ["x"],
"address": { "city": "Pune", "pin": "411001" },
"createdAt": "2026-01-15T10:30:00Z"
}class Address {
final String city;
final String pin;
Address({
required this.city,
required this.pin,
});
factory Address.fromJson(Map<String, dynamic> json) {
return Address(
city: json["city"] as String,
pin: json["pin"] as String,
);
}
Map<String, dynamic> toJson() => {
"city": city,
"pin": pin,
};
}
class Root {
final int id;
final String name;
final String? email;
final List<String> tags;
final Address address;
final String createdAt;
Root({
required this.id,
required this.name,
this.email,
required this.tags,
required this.address,
required this.createdAt,
});
factory Root.fromJson(Map<String, dynamic> json) {
return Root(
id: json["id"] as int,
name: json["name"] as String,
email: json["email"] as String?,
tags: (json["tags"] as List<dynamic>).map((e) => e as String).toList(),
address: Address.fromJson(json["address"] as Map<String, dynamic>),
createdAt: json["createdAt"] as String,
);
}
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"email": email,
"tags": tags,
"address": address.toJson(),
"createdAt": createdAt,
};
}
Common mistakes
- A single sample cannot show which fields are optional. Paste two or three different responses for a realistic result.
- A value that is always null gives no type information, so it is treated as a nullable string. Change it by hand if it is something else.
- Numbers are typed from the samples: 1 and 1.0 look the same in JSON, so use a sample with decimals where you need a float.