Model From JSON ๐
A zero-setup Dart CLI tool that generates clean, Equatable-ready Dart model classes directly from JSON.
โ
No annotations
โ
No build_runner
โ
No .g.dart files
โ
Just instant model generation
โก Generates models in under 1 second for most API JSON files โ no codegen pipeline needed.
โจ Why Model From JSON?
Most Flutter model generators require:
- Annotations (
@JsonSerializable) build_runnercommands- Generated
.g.dartpart files - Extra boilerplate setup
model_from_json is different:
โ
Works instantly
โ
Outputs plain Dart files immediately
โ
Perfect for rapid development and API prototyping
๐ฌ Demo
Generate models instantly:
model_from_json complex.json --name ApiResponse --out lib/models
Output:
โ
Done! Generated 6 model files:
๐ api_response.dart
๐ meta.dart
๐ user.dart
๐ accounts.dart
๐ subscription.dart
๐ features.dart
โ Features
-
โ Generate Dart model classes automatically from JSON
-
โ Supports nested objects (
profile,subscription, etc.) -
โ Supports lists of nested objects (
accounts,features, etc.) -
โ Generates complete boilerplate:
fromJson()toJson()(with nested serialization)- Equatable
props
-
โ Generates multiple
.dartfiles recursively -
โ Supports both:
- Command mode
- Interactive mode
-
โ Optional output folder support (
--out)
๐ฆ Installation
Activate globally:
dart pub global activate model_from_json
Run anywhere:
model_from_json <json_path> --name ClassName
๐ Usage
โ Command Mode
Generate models into the current directory:
model_from_json complex.json --name ApiResponse
Generate models into a folder:
model_from_json complex.json --name ApiResponse --out lib/models
โ Interactive Mode
Run without arguments:
model_from_json
You will be guided step-by-step:
Enter JSON file path: ultra.json
Enter root class name: ApiResponse
Enter output folder [.] : lib/models
๐งพ Example Input
complex.json
{
"meta": {
"request_id": "REQ-123",
"success": true
},
"user": {
"id": 101,
"name": "Dipesh Panchal",
"roles": ["trader", "developer"]
},
"accounts": [
{
"broker": "zerodha",
"balance": 250000.75
}
],
"subscription": {
"plan": "pro",
"features": [
{
"name": "nested_models",
"enabled": true
}
]
}
}
โ Example Output
api_response.dart
class ApiResponse extends Equatable {
final Meta meta;
final User user;
final List<Accounts> accounts;
final Subscription subscription;
const ApiResponse({
required this.meta,
required this.user,
required this.accounts,
required this.subscription,
});
factory ApiResponse.fromJson(Map<String, dynamic> json) {
return ApiResponse(
meta: Meta.fromJson(json['meta'] ?? {}),
user: User.fromJson(json['user'] ?? {}),
accounts: (json['accounts'] as List? ?? [])
.map((e) => Accounts.fromJson(e))
.toList(),
subscription: Subscription.fromJson(json['subscription'] ?? {}),
);
}
}
๐ Output Structure
Generated folder example:
lib/models/
โโโ api_response.dart
โโโ meta.dart
โโโ user.dart
โโโ accounts.dart
โโโ subscription.dart
โโโ features.dart
โ๏ธ CLI Options
| Option | Description |
|---|---|
--name |
Root class name (required) |
--out |
Output folder (optional) |
--help |
Show CLI usage instructions |
โ Roadmap
Planned future improvements:
- Nullable type inference (
String? phone) - Dictionary/Map field support (
Map<String,dynamic> metadata) - Smarter naming (
daily_pnl โ DailyPnl) - Barrel export generation (
models.dart) - Optional Freezed/json_serializable generation mode
๐ค Contributing
Pull requests and improvements are welcome!
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 the Flutter community ๐