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)