json2model
1.1.4, released 11 days ago by venshine.cn
Generates Dart model classes from JSON strings via command line
What it does
This package parses a JSON file and outputs Dart model classes with toJson and fromJson methods. It supports null safety, optional and final fields, and handles keys that are not valid Dart identifiers.
AI-written summary of version 1.1.4, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to quickly generate typed models from a JSON schema
- You want compile‑time safety for JSON data
- You are prototyping a Flutter app and want to avoid manual boilerplate
Skip it when
- You prefer hand‑written models for fine‑grained control
- You need runtime JSON parsing without code generation
- You are building a library that must not depend on a code‑generation tool
Strengths
- Supports null safety and optional fields
- Generates toJson/fromJson automatically
- Handles non‑identifier keys and integer values for double fields
- Command‑line tool is easy to use
Weaknesses
- Only a command‑line tool, not integrated with build_runner
- No support for runtime JSON parsing
- Requires manual regeneration when JSON changes
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Run `run(['--src=example/json', '--dst=example/lib/models']);` or use the CLI `json2model` command
```dart
import 'package:json2model/json2model.dart';
void main() {
run(['--src=example/json', '--dst=example/lib/models']);
}
```Alternatives
Packages that do the same job and could replace json2model.
- json_serializable
Automatically generate code for converting Dart classes to and from JSON.
94Compare - protoc_plugin
Generates Dart source files from Protocol Buffer (.proto) definitions using the protoc compiler.
80Compare - flutter_gen_runner
Generates strongly-typed Dart classes for Flutter assets, fonts, and colors to avoid string-based APIs.
87Compare - flutter_gen
A code generator for your assets, fonts, and colors to eliminate string-based APIs.
87Compare
Works with
Packages commonly used together with json2model: ones it builds on, ones built on it, and its own family.