I have been driving myself crazy trying to find a module that I can use with nested objects specifically classes. There are a few modules that are pretty close however I do not want to set the properties to null to skip the values I do not want.
It would be great if I could write a TO_JSON method or so to that returns a structure that will be marshaled by a module. Or, just use "json-skip" on attributes we don't want included in the final JSON document.
Something like:
class Something {
has Str $.foo;
has Str $.bar is json-skip;
}
or
class Something {
has Str $.foo;
has Str $.bar;
method TO_JSON {
return {
foo => $.foo
}
}
}
JSON::Tiny, JSON::Fast, JSON::Marshal, etc... all work great with individual structures and some even with nested instances however excluding properties is eluding me at the moment.
At the end I would like to do something like:
my $json-document = to-json(@nestedInstances);