fson 0.4.2

  • Readme
  • Changelog
  • Installing
  • new43

Language: English | 中文简体

fson Pub #

Gernerating Dart model class from Json file.

Installing #

flutter pub global activate fson or pub global activate fson

dev_dependencies:
  build_runner: any
  json_serializable: any

Getting Started #

  1. Create a "jsons" directory in the root of your project;
  2. Create a Json file under "jsons" dir ;
  3. Run fson

Examples #

File: jsons/user.json

{
  "name":"wendux",
  "father":"$user", //Other class model 
  "friends":"$[]user", // Array  
  "keywords":"$[]String", // Array
  "age":20
}

Run pub run fson, then you'll see the generated json file under lib/models/ dir:

import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';

@JsonSerializable()
class User {
    User();
    
    String name;
    User father;
    List<User> friends;
    List<String> keywords;
    num age;
    
    factory User.fromJson(Map<String,dynamic> json) => _$UserFromJson(json);
    Map<String, dynamic> toJson() => _$UserToJson(this);
}

@JsonKey #

You can also use “@JsonKey” annotation from json_annotation package.

{
  "@JsonKey(ignore: true) dynamic":"md",
  "@JsonKey(name: '+1') int": "loved",
  "name":"wendux",
  "age":20
}

The generated class is:

import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';

@JsonSerializable()
class User {
    User();

    @JsonKey(ignore: true) dynamic md;
    @JsonKey(name: '+1') int loved;
    String name;
    num age;
    
    factory User.fromJson(Map<String,dynamic> json) => _$UserFromJson(json);
    Map<String, dynamic> toJson() => _$UserToJson(this);
}

Test:

import 'models/index.dart';

void main() {
  var u = User.fromJson({"name": "Jack", "age": 16, "+1": 20});
  print(u.loved); // 20
}

@Import #

{
  "@import":"test_dir/profile.dart", //import file for model class
  "@JsonKey(ignore: true) Profile":"profile",
  "name":"wendux",
  "age":20
}

The generated class:

import 'package:json_annotation/json_annotation.dart';
import 'test_dir/profile.dart';  // import file
part 'user.g.dart';

@JsonSerializable()
class User {
    User();

    @JsonKey(ignore: true) Profile profile; //file
    String name;
    num age;
    
    factory User.fromJson(Map<String,dynamic> json) => _$UserFromJson(json);
    Map<String, dynamic> toJson() => _$UserToJson(this);
}

For completed examples see here .

Command arguments #

The default json source file directory is project_root/jsons; you can custom the src file directory by src argument, for example:

fson src=json_files 

You can also custom the dist directory by dist argument:

fson src=json_files  dist=data # will save in lib/data dir

The dist root is lib

[0.4.2] #

  • update version

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate fson

2. Use it

The package has the following executables:


$ fson

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fson: ^0.4.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fson/build_runner.dart';
import 'package:fson/graph_inspector.dart';
import 'package:fson/index.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
74
Overall:
Weighted score of the above. [more]
43
Learn more about scoring.

We analyzed this package on Jul 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/package_graph/build_config_overrides.dartpackage:build_runner_core/build_runner_core.dartpackage:build_runner_core/src/generate/build_runner.dartpackage:build_runner_core/src/generate/build_impl.dartpackage:build_runner_core/src/generate/build_definition.dartpackage:build_runner_core/src/changes/build_script_updates.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/package_graph/build_config_overrides.dartpackage:build_runner_core/build_runner_core.dartpackage:build_runner_core/src/generate/build_runner.dartpackage:build_runner_core/src/generate/build_impl.dartpackage:build_runner_core/src/generate/build_definition.dartpackage:build_runner_core/src/changes/build_script_updates.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/package_graph/build_config_overrides.dartpackage:build_runner_core/build_runner_core.dartpackage:build_runner_core/src/generate/build_runner.dartpackage:build_runner_core/src/generate/build_impl.dartpackage:build_runner_core/src/generate/build_definition.dartpackage:build_runner_core/src/changes/build_script_updates.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/package_graph/build_config_overrides.dartpackage:build_runner_core/build_runner_core.dartpackage:build_runner_core/src/generate/build_runner.dartpackage:build_runner_core/src/generate/build_impl.dartpackage:build_runner_core/src/generate/build_definition.dartpackage:build_runner_core/src/changes/build_script_updates.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/package_graph/build_config_overrides.dartpackage:build_runner_core/build_runner_core.dartpackage:build_runner_core/src/generate/build_runner.dartpackage:build_runner_core/src/generate/build_impl.dartpackage:build_runner_core/src/generate/build_definition.dartpackage:build_runner_core/src/changes/build_script_updates.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/build_script_generate/builder_ordering.dartpackage:build_config/build_config.dartpackage:build_config/src/build_config.dartdart:io

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/package_graph/build_config_overrides.dartpackage:build_runner_core/build_runner_core.dartpackage:build_runner_core/src/generate/build_runner.dartpackage:build_runner_core/src/generate/build_impl.dartpackage:build_runner_core/src/generate/build_definition.dartpackage:build_runner_core/src/changes/build_script_updates.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:fson/build_runner.dartpackage:fson/src/commands/generate_build_script.dartpackage:build_runner/src/build_script_generate/build_script_generate.dartpackage:build_runner/src/build_script_generate/builder_ordering.dartpackage:build_config/build_config.dartpackage:build_config/src/build_config.dartdart:io

Health suggestions

Fix bin/fson.dart. (-2.96 points)

Analysis of bin/fson.dart reported 6 hints, including:

line 53 col 16: Unnecessary new keyword.

line 102 col 19: Unnecessary new keyword.

line 186 col 19: Unnecessary new keyword.

line 187 col 30: Unnecessary new keyword.

line 311 col 13: Unnecessary new keyword.

Fix lib/index.dart. (-2.48 points)

Analysis of lib/index.dart reported 5 hints:

line 14 col 16: Unnecessary new keyword.

line 56 col 17: Unnecessary new keyword.

line 57 col 28: Unnecessary new keyword.

line 159 col 13: Unnecessary new keyword.

line 161 col 11: Unnecessary new keyword.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (build_runner_core).

The package description is too short. (-16 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and fson.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
args ^1.6.0 1.6.0
build ^1.2.2 1.2.2 1.3.0
build_resolvers ^1.3.3 1.3.7 1.3.10
build_runner ^1.8.0 1.8.0 1.10.0
build_runner_core ^4.5.2 4.5.3 6.0.0
glob ^1.2.0 1.2.0
io ^0.3.3 0.3.4
json_annotation ^3.0.1 3.0.1
json_serializable ^3.2.5 3.3.0
logging ^0.11.4 0.11.4
path ^1.6.4 1.7.0
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.12
async 2.4.2
build_config 0.4.2
build_daemon 2.1.4
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
checked_yaml 1.0.2
code_builder 3.3.0
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
fixnum 0.10.11
graphs 0.2.0
html 0.14.0+3
http_multi_server 2.2.0
http_parser 3.1.4
js 0.6.2
matcher 0.12.8
meta 1.2.1
mime 0.9.6+3
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pedantic 1.9.1
pool 1.4.0
pub_semver 1.4.4
pubspec_parse 0.1.5
quiver 2.1.3
shelf 0.7.7
shelf_web_socket 0.2.3
source_gen 0.9.5
source_span 1.7.0
stack_trace 1.9.5
stream_channel 2.0.0
stream_transform 1.2.0
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.2.0
watcher 0.9.7+15
web_socket_channel 1.1.0
yaml 2.2.1