easy_json 1.0.1

A JSON serialization library for Dart developers. #

Based on reflection (by dart:mirrors), serialized and parse json easily without generate code.

Usage #

A simple usage example:

import 'package:easy_json/easy_json.dart';

main() {
  var simple = SimpleExample(
    0x01001,
    'name',
    ['item0'],
    {'name0': 'value0'},
    SimpleNested(0x02001),
  );
  var simpleEncoded = toJsonString(simple);
  print(simpleEncoded);
  var simpleDecoded = ofJsonString(SimpleExample, simpleEncoded);
  print(simpleDecoded);
}

class SimpleExample {
  final int id;
  final String name;
  final List<String> list;
  final Map<String, dynamic> map;
  final SimpleNested nested;
  @JsonIgnore
  final String ignored;

  SimpleExample(
    this.id,
    this.name,
    this.list,
    this.map,
    this.nested, [
    this.ignored,
  ]);
}

class SimpleNested {
  final int id;

  SimpleNested(this.id);
}

Features and TODO List #

  • [x] toJson (serialized object without generate code)
  • [x] ofJson (parse from json map without generate code)
  • [x] nested (auto serialized and parse the nested type)
  • [x] @JsonIgnored (ingored some fields when serialized and parse)
  • [x] @JsonField (custom the of and to function of some fields)
  • [x] @JsonModel (custom the of and to function of some class)
  • [x] @EasJson<It, Json> (full support of explicit generic type)
  • [ ] redirecting support (syntax like factory Constructor = aConstructor)
  • [ ] cache (cache the reflection shape of the model to speed up the next usage)

1.0.0 #

  • Initial version, created by Stagehand

example/easy_json_example.dart

import 'package:easy_json/easy_json.dart';

import 'model.dart';

main() {
  var string = toJsonString(Model.init);
  print('Stringify `Model.init`: ${string}');
}

Use this package as a library

1. Depend on it

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


dependencies:
  easy_json: ^1.0.1

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:easy_json/easy_json.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: web, other

Primary library: package:easy_json/easy_json.dart with components: mirrors.

Health issues and suggestions

Document public APIs. (-1 points)

22 out of 22 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

The package description is too short. (-11 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.0.0