jsonx 1.0.1 jsonx: ^1.0.1 copied to clipboard
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.