dart_json 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

GitHub license Travis Pub Coverage Status

DartJson #

DartJson is a JSON to object mapper.

  • It's fast
  • dependency-less
  • works with nested objects
  • property names in classes can be different to the name in the json

📦 Installation #

Add the following to your pubspec.yaml:

dependencies:
  dart_json: ^1.0.0

Then run pub get

💡 Usage #

Importing #

import 'package:dart_json/dart_json.dart';

Using it #

import 'package:dart_json/dart_json.dart';

class Person {
  @JsonProperty("first_name")
  String firstName;

  String lastName;

  int age;
}

void main() {
  var json = '{"first_name": "Max", "lastName": "Mustermann", "age": 25}';
  Person p = Json.deserialize<Person>(json);
  print(p.firstName); // Max
  print(p.lastName); // Mustermann
  print(p.age); // 25

  var newJson = Json.serialize(p);
  print(newJson); // {"first_name":"Max","lastName":"Mustermann","age":25}
}

🔬 Testing #

$ pub run test

🤝 Contribute #

Feel free to fork and add pull-requests 🤓

1.0.1 #

  • Dart 2.0 support added
  • example/main.dart added
  • Pub issues and suggestions resolved

1.0.0 #

  • Initial release

example/main.dart

import 'package:dart_json/dart_json.dart';

class Person {
  @JsonProperty("first_name")
  String firstName;

  String lastName;

  int age;
}

void main() {
  var json = '{"first_name": "Max", "lastName": "Mustermann", "age": 25}';
  Person p = Json.deserialize<Person>(json);
  print(p.firstName); // Max
  print(p.lastName); // Mustermann
  print(p.age); // 25

  var newJson = Json.serialize(p);
  print(newJson); // {"first_name":"Max","lastName":"Mustermann","age":25}
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Fix lib/json.dart. (-6.78 points)

Analysis of lib/json.dart reported 14 hints, including:

line 20 col 13: Don't explicitly initialize variables to null.

line 60 col 20: Unnecessary new keyword.

line 69 col 13: Don't explicitly initialize variables to null.

line 109 col 40: Prefer to use whereType on iterable.

line 136 col 16: Use isNotEmpty instead of length

Fix lib/annotation/json_property.dart. (-0.50 points)

Analysis of lib/annotation/json_property.dart reported 1 hint:

line 15 col 23: Don't type annotate initializing formals.

Fix lib/dart_json.dart. (-0.50 points)

Analysis of lib/dart_json.dart reported 1 hint:

line 10 col 9: Name libraries using lowercase_with_underscores.

Maintenance suggestions

Package is getting outdated. (-19.73 points)

The package was last published 62 weeks ago.

Dependencies

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