toJSON

Convert a user-defined type to json. See jsonizer.jsonize for info on how to mark your own types for serialization.

Examples

Serialize an instance of a user-defined type to a json object.

1 import jsonizer.jsonize;
2 
3 static struct Foo {
4   mixin JsonizeMe;
5   @jsonize int i;
6   @jsonize string[] a;
7 }
8 
9 auto foo = Foo(12, [ "a", "b" ]);
10 assert(foo.toJSON() == `{"i": 12, "a": [ "a", "b" ]}`.parseJSON);

Meta