Skip to content

scnon/json_dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File with heading

This is a simple package to help build dart model from json.

Features

About json file you can add some sign to assign default or nullable or not like this:

{
  "r@id": 1,
  "d@sex": 1,
  "name": "Jack"
}

you will get like this:

class ExampleModel {
final int id;
final int sex;
final String? name;
ExampleModel({required this.id, this.sex = 1, this.name})
}

And you can use custom class List like this:

{
  "list": "[]example"
}
final List<ExampleModel> list;

Also it support nested object like this:

{
  "list": {
    "length": 3,
    "body": []
  }
}

It will auto generate a class named ListItemModel

Getting started

Usage

  1. Add to your pubspec.yaml
dev_dependencies:
  build_runner: any
  json_dart:
    git:
      url: git://github.com/scnon/json_dart.git
  1. You need put some json file to your jsons folder.like this:
├── jsons
│   ├── class.json
│   └── user.json
├── libs
│   └── main.dart
  1. Just run it like this:
dart run build_runner build
  1. You will see you json model file in lib/models/

  2. Enjoy it.

About

A json to dart model generator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages