{ }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

Paste a JSON object to generate Freezed model declarations. Copy the output into a Dart file whose name matches the generated part directives.

Output behavior

Each inferred object becomes an @Freezed class with a fromJson factory. The file declares matching .freezed.dart and .g.dart parts. @JsonKey(name: ...) keeps original JSON keys when Dart fields use camelCase. The output sets makeCollectionsUnmodifiable to false.

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

Before using it

Run build_runner from the project root after saving the file. Keep the generated part files with the source file; changing the root class name changes their expected filenames.