dart_json_annotations library

High-performance code generation for Dart/Flutter models.

Generates JSON serialization, copyWith, equatable, and union methods using a Rust-powered CLI for maximum speed.

Quick Start

import 'package:dart_json_annotations/dart_json_annotations.dart';

@Model()  // JSON only (default)
class User {
  final String name;
  final int age;
  User({required this.name, required this.age});
}

Model Presets

Preset Features Lines/Model
@Model() JSON only ~25
@Model.data() JSON + copyWith + equatable ~50
@Model.bloc() copyWith + equatable (no JSON) ~35
@Model.union() when/map methods for sealed classes ~60

Classes

Ignore
Ignore this field from specific features.
JsonEnum
Marks an enum for JSON serialization with custom value mapping.
JsonFlatten
Marks a field to be flattened into the parent JSON object.
JsonKey
Customizes JSON serialization for a specific field.
JsonType
Sets the naming convention for JSON field serialization.
JsonValue
Custom JSON value for enum variants.
Model
Main annotation for code generation.
UnionCase
Marks a class as a union case (subtype of sealed class).

Enums

JsonEnumValue
NamingConvention
Defines the naming convention for JSON serialization.