Flutter 3.50 is live! Read the blog post

Dart Data Class Generator

Paste JSON to generate an immutable Dart data class — constructor, copyWith, toString, and equality.

No fromJson/toJson here — for JSON (de)serialization, use the JSON to Dart Converter instead.

Generated Dart
// Click "Generate" to see the Dart class

Related Tools

// more about this tool

Why use this tool

An immutable data class needs more than final fields. It needs a copyWith method so you can produce a modified copy without mutating the original (essential for state management patterns like Bloc or Riverpod, where state objects should never be mutated in place), a working == operator and hashCode so two instances with the same field values are treated as equal instead of only being equal by reference, and a readable toString for debugging. Writing all of that correctly by hand, especially the equality check across every field, is tedious and easy to get subtly wrong — it's easy to forget a field in the equality check after adding it to the class.

Paste a JSON sample and this generates a Dart class with typed final fields inferred from the JSON's actual values, a constructor, copyWith, a value-based == and hashCode covering every field, and toString — all the plumbing an immutable value class needs, without the fromJson/toJson serialization.

How it works

  1. Set the class name.
  2. Paste a JSON sample into the input panel.
  3. Click Generate to produce the class.
  4. Copy the result and paste it into your Dart project.

Example

Input

{ "id": 1, "name": "Bilal Fali", "isActive": true }

Generated class (excerpt)

class User {
  const User({
    required this.id,
    required this.name,
    required this.isActive,
  });

  final int id;
  final String name;
  final bool isActive;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is User &&
          other.id == id &&
          other.name == name &&
          other.isActive == isActive;
}

FAQ

Why no fromJson/toJson?

This tool is specifically for the immutable-class shape — constructor, copyWith, equality, toString — not JSON serialization. Pair it with the JSON to Dart Converter on this site if you also need fromJson/toJson for the same shape.

How does equality work across nested lists or maps?

The generated == operator compares list and map fields with Dart's default == operator, which for List and Map is reference equality, not deep equality. Two instances holding separately-constructed lists with identical contents will not compare equal — if you need deep list/map equality, wrap those fields with a package like collection's ListEquality, or switch to Freezed.

Does copyWith let me set a field back to null?

No — the generated copyWith uses the common field ?? this.field pattern, where passing null for an argument falls back to the existing value rather than clearing it. Setting a field to null specifically requires a different copyWith pattern (a sentinel value) that this tool doesn't generate.

When should I use this instead of Freezed?

Use this when you want a plain, dependency-free immutable class with no code generation step. Reach for Freezed instead when you need deep equality for free, union types, or you're already running build_runner for other generated code in the project.

Does it handle nested objects?

Yes — a nested object in your sample becomes its own generated class, named after its key, with the same copyWith/equality/toString treatment as the root class. The output lists every generated class, root last.