dart_serializer
dart_serializer is a Dart package designed to streamline the creation of Dart data models from JSON files using a convenient command-line interface (CLI). It simplifies the process of generating Dart classes that accurately represent the structure of JSON data, making it easier to work with JSON APIs and datasets in Dart projects.
Features
- Automatic Dart Class Generation: Quickly generate Dart classes from JSON files.
- Support for Nested Structures: Handle nested objects, arrays, and diverse data types effortlessly.
- Customizable Naming Conventions: Adapt class and field names to suit your project's conventions.
- Seamless CLI Integration: Easily incorporate data model generation into your workflow.
Installation
Ensure you have Dart installed on your system. If not, download it from the Dart website. Once Dart is installed, activate dart_serializer globally:
Usage
After installing dart_serializer
, you can use the dart run dart_serializer:generate
command-line tool to generate Dart data models from JSON files. Here's how you can use it:
-
Prepare Your JSON File: Create a JSON file defining the structure of your data. For example,
example.json
:{ "name": "John Doe", "age": 30, "address": { "street": "123 Main St", "city": "Anytown", "state": "Anystate", "zipcode": "12345" } }
-
Run the
dart run dart_serializer:generate path/to/your/file.dart
command with the path to your JSON file as an argument: -
dart_serializer
will generate Dart classes based on the structure of your JSON data. The generated classes will be saved in the current directory. -
You can now use the generated Dart classes in your Dart code to parse JSON data into Dart objects and vice versa.
-
Null Safety: You can also generate Nullable Dart classes by passing
nullable
argument. For example,dart run dart_serializer:generate path/to/your/file.dart nullable
Contributing
If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.