{ }input.json
Copy JSON input to clipboard. Replace JSON input with clipboard text. Remove all JSON input. Load the default example JSON.
Dorder.dart
Copy generated Dart code to clipboard. Hide generated class list.
import 'package:freezed_annotation/freezed_annotation.dart';
part 'order.freezed.dart';
part 'order.g.dart';

@Freezed(makeCollectionsUnmodifiable: false)
abstract class Order with _$Order {
  const factory Order({
    @JsonKey(name: "order_id")
    required String orderId,
    required Customer customer,
    required double total,
    @JsonKey(name: "created_at")
    required DateTime createdAt,
    required List<Item> items,
  }) = _Order;

  factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json);
}

@Freezed(makeCollectionsUnmodifiable: false)
abstract class Customer with _$Customer {
  const factory Customer({
    @JsonKey(name: "first_name")
    required String firstName,
    required String email,
    @JsonKey(name: "is_verified")
    required bool isVerified,
  }) = _Customer;

  factory Customer.fromJson(Map<String, dynamic> json) => _$CustomerFromJson(json);
}

@Freezed(makeCollectionsUnmodifiable: false)
abstract class Item with _$Item {
  const factory Item({
    required String sku,
    required int quantity,
    required double price,
    String? note,
  }) = _Item;

  factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json);
}

Convert JSON to Freezed 3.x

This mode writes @Freezed classes, fromJson factories, and part directives for the matching .freezed.dart and .g.dart files. Original JSON keys are preserved with @JsonKey when Dart field names differ.

Copy the output into a Dart file using the generated filename. Add the runtime annotations and Freezed 3.x build dependencies in your Flutter project, then run build_runner to create the part files.

Project setup

flutter pub add freezed_annotation json_annotation
flutter pub add --dev freezed:^3.2.5 build_runner json_serializable
dart run build_runner build