json_model_gen 0.0.6 copy "json_model_gen: ^0.0.6" to clipboard
json_model_gen: ^0.0.6 copied to clipboard

A Dart tool to generate model classes from JSON with fromJson, toJson, copyWith, and equality overrides.

๐Ÿงฌ json_model_gen

Generate Dart model classes effortlessly from raw JSON using this CLI tool.

โœจ Features

๐Ÿ”„ Converts JSON into Dart classes โ„๏ธ Supports freezed annotation โ™ป๏ธ Supports equatable ๐Ÿ”’ Optional field nullability ๐Ÿ’ฌ Interactive prompts (if no flags provided) ๐Ÿ›‘ Prevents accidental overwrites ๐Ÿ“ Auto-renames .json โ†’ .dart when needed

๐Ÿš€ Installation

To install from pub.dev, run:

dart pub add json_model_gen Or manually add it to your pubspec.yaml:

dependencies: json_model_gen: ^0.0.6 Then run:

dart pub get

๐Ÿ”ง Usage

๐Ÿ“ฆ Full command with flags: dart run json_model_gen
--input=raw.json
--output=lib/user_model.dart
--class=UserModel
--freezed
--equatable
--nullable

๐Ÿง  Or use interactive mode: Just run:

dart run json_model_gen It will ask you step-by-step:

๐Ÿ“ฅ Input file path ๐Ÿ“ค Output file path ๐Ÿงช Class name โš™๏ธ Use equatable โ„๏ธ Use freezed โ“ Make all fields nullable ๐Ÿ“Œ Example

Input (raw.json) { "id": 1, "name": "Alice", "active": true, "bio": null } Output (user_model.dart) import 'package:freezed_annotation/freezed_annotation.dart';

part 'user_model.freezed.dart'; part 'user_model.g.dart';

@freezed class UserModel with _$UserModel { const factory UserModel({ int? id, String? name, bool? active, String? bio, }) = _UserModel;

factory UserModel.fromJson(Map<String, dynamic> json) => _$UserModelFromJson(json); }

โš ๏ธ Notes

โœ… Input file must contain ONLY valid JSON, not Dart code. ๐Ÿ“„ If your input file ends with .dart, it will still work, but a warning will appear. ๐Ÿงช Class names are validated to be in PascalCase. ๐Ÿ“Œ --output=model.json will auto-convert to model.dart.

โญ Star the repo on GitHub if you like it!

4
likes
0
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart tool to generate model classes from JSON with fromJson, toJson, copyWith, and equality overrides.

Repository (GitHub)
View/report issues

Topics

#json #model #codegen #dart #cli

License

unknown (license)

Dependencies

args, recase

More

Packages that depend on json_model_gen