DEV Community

V . Raagull Sakthivel
V . Raagull Sakthivel

Posted on

🧬 Generate Dart Models from JSON β€” Meet json_model_gen

I just released json_model_gen, a CLI tool that turns raw JSON into clean Dart model classes β€” right from your terminal.

✨ Why use it?

πŸ”„ Convert raw JSON into Dart models
❄️ Supports freezed
♻️ Supports equatable
πŸ”’ Optional field nullability
πŸ’¬ Interactive mode if you skip flags
πŸ›‘ Prevents accidental file overwrites
πŸ“ Auto-renames .json β†’ .dart when needed

πŸš€ Quick Start

dart pub add json_model_gen
Enter fullscreen mode Exit fullscreen mode

Run it:

dart run json_model_gen
Enter fullscreen mode Exit fullscreen mode

Or use all flags:

dart run json_model_gen \
  --input=raw.json \
  --output=lib/user_model.dart \
  --class=UserModel \
  --freezed \
  --equatable \
  --nullable
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Example Output

Given:

{ "id": 1, "name": "Alice", "active": true }
Enter fullscreen mode Exit fullscreen mode

You get:

@freezed
class UserModel with _$UserModel {
  const factory UserModel({ int? id, String? name, bool? active }) = _UserModel;
  factory UserModel.fromJson(Map<String, dynamic> json) => _$UserModelFromJson(json);
}
Enter fullscreen mode Exit fullscreen mode

🧠 Why I built this``

I wanted a tool that fits right into your local dev workflow β€” no switching tabs, just raw JSON β†’ model class in seconds. Also useful to keep the JSON alongside models for better documentation.

Try it out from pub.dev and let me know what you think! πŸ’¬
[(https://pub.dev/packages/json_model_gen)]
Feedback, ideas, and PRs are always welcome πŸš€

Top comments (0)