json2entity 1.1.2 copy "json2entity: ^1.1.2" to clipboard
json2entity: ^1.1.2 copied to clipboard

A tool for converting JSON strings into dart entity classes. Support json_serializable.

json2entity #

pub version

中文

A tool for converting JSON strings into dart entity classes

support json_serializable.

无需手写,自动生成Flutter/Dart实体类文件 -- 掘金

Usage #

    1. dependencies
dependencies:
  json2entity: ^1.0.9
    1. activate json2entity global.

pub global activate json2entity

    1. run anywhere:
# output to stdout
j2e -j '{"result":1,"msg":"ok"}'

# output to file
j2e -j '{"result":1,"msg":"ok"}' -o output/BaseEntity

Windows users: #

If you are a Windows user, you need to escape the JSON string you entered

j2e -j '{\"result\":1,\"msg\":\"ok\"}'

SYNOPSIS:

Usage:
        -j, --json                              Input json string
        -f, --file                              Input json from file
        -o, --output                            Input output file path and name
        -v, --[no-]verbose                      Show verbose
        -s, --[no-]json-serializable-support    Indicates whether json-serializable is supported
        -c, --[no-]camelize                     convert underscore to camel case
        -h, --[no-]help                         Help

Custom

import 'package:json2entity/json2entity.dart';

main(List<String> args) {
  var jsonStr = '{"result":1,"msg":"ok"}';
  print(Clazz.fromJson(jsonStr).toString()); 
  print(JsonSerializableClazz.fromJson(jsonStr).toString()); 
}

Output:

  class AutoModel {
    num result;
    String msg;
    AutoModel({
    this.result,
    this.msg
    });

    AutoModel.fromJson(Map < String, dynamic > json):
      result=json['result'],
      msg=json['msg'];
      Map <String, dynamic> toJson() => {
      'result':result,
      'msg':msg
    };
  }

  @JsonSerializable()
  class AutoModel {
    num result;
      String msg;
      AutoModel({
      this.result,
      this.msg
    });

    factory AutoModel.fromJson(Map<String, dynamic> json) => _$AutoModelFromJson(json);
      Map<String, dynamic> toJson() => _$AutoModelToJson(this);
    }

Main classes #

Clazz

Converting JSON strings into entity classes.

JsonSerializableClazz

Inheriting from Clazz, transforming JSON strings into entity classes that support json_serializable

Example #

wiki

Test #

./test_all.sh

4
likes
30
pub points
29%
popularity

Publisher

unverified uploader

A tool for converting JSON strings into dart entity classes. Support json_serializable.

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

args, dart_style, path

More

Packages that depend on json2entity