input.json
order.dart
extension type const Order(Map<String, dynamic> json) { factory Order.fromJson(Map<String, dynamic> json) => Order(json); String get orderId => json["order_id"] as String; Customer get customer => Customer.fromJson(json["customer"] as Map<String, dynamic>); double get total => (json["total"] as num).toDouble(); DateTime get createdAt => DateTime.parse(json["created_at"] as String); List<Item> get items => (json["items"] as List<dynamic>).map((e) => Item.fromJson(e as Map<String, dynamic>)).toList(); Map<String, dynamic> toJson() => json; } extension type const Customer(Map<String, dynamic> json) { factory Customer.fromJson(Map<String, dynamic> json) => Customer(json); String get firstName => json["first_name"] as String; String get email => json["email"] as String; bool get isVerified => json["is_verified"] as bool; Map<String, dynamic> toJson() => json; } extension type const Item(Map<String, dynamic> json) { factory Item.fromJson(Map<String, dynamic> json) => Item(json); String get sku => json["sku"] as String; int get quantity => json["quantity"] as int; double get price => (json["price"] as num).toDouble(); String? get note => json["note"] == null ? null : json["note"] as String; Map<String, dynamic> toJson() => json; }
Convert JSON to Dart extension types
Paste JSON to generate typed views over decoded maps. This output requires Dart 3.3 or newer and needs no package or build step.
Output behavior
Each extension type uses Map<String, dynamic> as its representation and exposes inferred fields through getters. Nested objects get nested extension types. The toJson method returns the underlying map rather than constructing a new one.
Before using it
Pass a decoded Map<String, dynamic> to the root fromJson factory. The getters read the original map, so later changes to that map remain visible through the extension type.