☰
Home
/
Code Generators
/
JSON → Dart
🎯
JSON → Dart
Generate Dart model class from JSON
☆
Bookmark
Loading tool…
JSON input
{ "id": 1, "name": "Ada Lovelace", "email": "ada@example.com", "isActive": true, "score": 98.6, "tags": ["admin", "developer"], "address": { "street": "123 Main St", "city": "London" }, "orders": [{ "id": 101, "total": 49.99, "shipped": false }] }
Dart output
⧉ Copy
class Address { final String street; final String city; const Address({ required this.street, required this.city, }); factory Address.fromJson(Map<String, dynamic> json) => Address( street: json['street'] as String, city: json['city'] as String, ); Map<String, dynamic> toJson() => { 'street': street, 'city': city, }; } class Order { final int id; final double total; final bool shipped; const Order({ required this.id, required this.total, required this.shipped, }); factory Order.fromJson(Map<String, dynamic> json) => Order( id: json['id'] as int, total: json['total'] as double, shipped: json['shipped'] as bool, ); Map<String, dynamic> toJson() => { 'id': id, 'total': total, 'shipped': shipped, }; } class Root { final int id; final String name; final String email; final bool isActive; final double score; final List<String> tags; final Address address; final List<Order> orders; const Root({ required this.id, required this.name, required this.email, required this.isActive, required this.score, required this.tags, required this.address, required this.orders, }); factory Root.fromJson(Map<String, dynamic> json) => Root( id: json['id'] as int, name: json['name'] as String, email: json['email'] as String, isActive: json['isActive'] as bool, score: json['score'] as double, tags: List<String>.from(json['tags'] as List), address: Address.fromJson(json['address'] as Map<String, dynamic>), orders: (json['orders'] as List).map((e) => Order.fromJson(e as Map<String, dynamic>)).toList(), ); Map<String, dynamic> toJson() => { 'id': id, 'name': name, 'email': email, 'isActive': isActive, 'score': score, 'tags': tags, 'address': address.toJson(), 'orders': orders.map((e) => e.toJson()).toList(), }; }