json/derive
A build plugin writing a JSON serialiser for each struct.
The code joins the struct's own module, which is what lets it name the type: a module of its own would have to import the struct's module, which imports it back.
Types
JsonDerive :: struct A build plugin giving every struct of modules a JSON serialiser: a
to_json_value(v) building a JsonValue, and a to_json(v) writing its text.
The functions are overloads on the struct type, generated into the struct's
own module. The mapping reads each field's type as written: a number, a
string, a bool, a struct of the same module (through its own overload), or
an array of one of them. Any other field is reported, and left out.
Example
expand
import "toolchain/build"
ctx :: new_build_context(["driver", "."])
ctx.use(JsonDerive { .modules = ["app"] })ctx.use(JsonDerive { .modules = ["app"] })Fields
modules: string[] The modules whose structs get a serialiser, by declared name.