Beyond primitives, lists, and maps

jsonx is an extended JSON library that supports the encoding and decoding of arbitrary objects. The best thing of jsonx is it allows code completion.

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
}

Libraries

jsonx

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