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
Run it:
dart run json_model_gen
Or use all flags:
dart run json_model_gen \
--input=raw.json \
--output=lib/user_model.dart \
--class=UserModel \
--freezed \
--equatable \
--nullable
📌 Example Output
Given:
{ "id": 1, "name": "Alice", "active": true }
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);
}
🧠 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)