jsonx 1.0.1 copy "jsonx: ^1.0.1" to clipboard
jsonx: ^1.0.1 copied to clipboard

discontinued
outdatedDart 1 only

An extended JSON library that supports the encoding and decoding of arbitrary objects.

Beyond Primitives, Lists, and Maps #

jsonx is an extended JSON library that supports the encoding and decoding of arbitrary objects. jsonx can decode a JSON string into an real object which gets type checking and code autocompletion support, or encode an arbitrary object into a JSON string.

Example #

import 'jsonx.dart';

class Person {
  String name;
  int age;
  List<Person> children;
}

main() {
  var c1 = new Person()
      ..name = 'child 1'
      ..age = 10;

  var c2 = new Person()
      ..name = 'child 2'
      ..age = 8;

  var p1 = new Person()
      ..name = 'parent'
      ..age = 40
      ..children = [c1, c2];

  var s1 = encode(p1);
  print(s1); // {"name":"parent","age":40,"children":[{"name":"child 1","age":10,"children":null},{"name":"child 2","age":8,"children":null}]}

  Person p2 = decode(s1, type: Person);
  print(p2.name); // parent

  var s2 = encode(p2);
  print(s2); // {"name":"parent","age":40,"children":[{"name":"child 1","age":10,"children":null},{"name":"child 2","age":8,"children":null}]}

  List<String> list = decode('["green", "yellow", "orange"]',
      type: <String>[].runtimeType);
  print(list[1]); // yellow
}

Contact #

For any issue or feedback, please contact me at Man Hoang jolleekin@outlook.com.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

An extended JSON library that supports the encoding and decoding of arbitrary objects.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on jsonx