model_from_json 1.0.1 copy "model_from_json: ^1.0.1" to clipboard
model_from_json: ^1.0.1 copied to clipboard

retracted

A Dart CLI tool that generates Equatable-ready Dart model classes directly from JSON files, with support for nested objects, lists, and automatic fromJson/toJson methods.

Model From JSON ๐Ÿš€ #

A lightweight Dart CLI tool that generates Equatable-ready Dart model classes directly from a JSON file.

Designed for Flutter developers who want:

โœ… Fast model generation
โœ… Nested model support
โœ… List of nested objects
โœ… fromJson() + toJson() built-in
โœ… Clean multi-file output
โœ… Interactive CLI mode


โœจ Features #

  • โœ… Generates Dart model classes automatically from JSON
  • โœ… Supports nested objects (profile, subscription, etc.)
  • โœ… Supports lists of nested objects (accounts, features, etc.)
  • โœ… Produces clean, Equatable-compatible models
  • โœ… Generates multiple .dart files recursively
  • โœ… Supports both:
    • Command mode
    • Interactive mode
  • โœ… Optional output folder support (--out)

๐Ÿ“ฆ Installation #

dart pub global activate model_from_json

Now you can run:

model_from_json <json_path> --name ClassName

๐Ÿš€ Usage #


โœ… Command Mode #

Generate models from JSON in the current folder:

model_from_json complex.json --name ApiResponse

Generate models into a custom folder:

model_from_json complex.json --name ApiResponse --out lib/models

โœ… Interactive Mode #

Run without arguments:

model_from_json

It will prompt you:

Enter JSON file path: ultra.json
Enter root class name: ApiResponse
Enter output folder [.] : lib/models

๐Ÿงพ Example Input #

complex.json #

{
  "user": {
    "id": 1,
    "name": "Dipesh"
  },
  "accounts": [
    {
      "broker": "zerodha",
      "balance": 250000
    }
  ]
}

โœ… Output Generated #

api_response.dart #

class ApiResponse extends Equatable {
  final User user;
  final List<Accounts> accounts;

  const ApiResponse({
    required this.user,
    required this.accounts,
  });

  factory ApiResponse.fromJson(Map<String, dynamic> json) {
    return ApiResponse(
      user: User.fromJson(json['user'] ?? {}),
      accounts: (json['accounts'] as List? ?? [])
          .map((e) => Accounts.fromJson(e))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() => {
        'user': user.toJson(),
        'accounts': accounts.map((e) => e.toJson()).toList(),
      };

  @override
  List<Object?> get props => [user, accounts];
}

๐Ÿ“‚ Output Structure #

Example generated folder:

lib/models/
 โ”œโ”€โ”€ api_response.dart
 โ”œโ”€โ”€ user.dart
 โ”œโ”€โ”€ accounts.dart
 โ””โ”€โ”€ broker_settings.dart

โš™๏ธ CLI Options #

Option Description
--name Root class name (required)
--out Output folder (optional)
--help Show usage help

โœ… Roadmap (Upcoming) #

Planned improvements:

  • Nullable type inference (String? phone)
  • Dictionary/Map field support (Map<String,dynamic> metadata)
  • Better naming rules (daily_pnl โ†’ DailyPnl)
  • Barrel export generation (models.dart)
  • Pub.dev v1.0 stable release

๐Ÿค Contributing #

Pull requests are welcome!

To contribute:

git clone https://github.com/yourusername/model_from_json.git
cd model_from_json
dart pub get
dart run

๐Ÿ“œ License #

MIT License ยฉ 2026 Dipesh Panchal


โญ Support #

If you find this tool useful, consider starring the repo and sharing it with Flutter developers!

1
likes
0
points
165
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart CLI tool that generates Equatable-ready Dart model classes directly from JSON files, with support for nested objects, lists, and automatic fromJson/toJson methods.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable

More

Packages that depend on model_from_json