A worked example, rendered from real sample data. Sign in to run the tool on your own input.
{"id":1,"name":"Flutter","stars":165000,"topics":["mobile","cross-platform"]}class Root {
final int id;
final String name;
final int stars;
final List<String> topics;
Root({required this.id, required this.name, required this.stars, required this.topics});
factory Root.fromJson(Map<String, dynamic> json) => Root(
id: json['id'],
name: json['name'],
stars: json['stars'],
topics: json['topics'],
);
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'stars': stars,
'topics': topics,
};
}
Generate a Dart class with fromJson/toJson from a JSON sample. Part of the DevTools Surf developer suite. Browse more tools in the Converters collection.