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.

import jsonizer.jsonize;

static struct Foo {
  mixin JsonizeMe;
  @jsonize int i;
  @jsonize string[] a;
}

auto foo = Foo(12, [ "a", "b" ]);
assert(foo.toJSON() == `{"i": 12, "a": [ "a", "b" ]}`.parseJSON);

Meta