Subject: | allow decoding to create custom blessed objects |
I'm ingesting large JSON feeds containing duplicate keys within objects.
Of course such duplicates are lost forever (ohno!) when the later
values are assigned during parsing.
I have tried to use the filter_json_object functionality to use a
Tie::Hash::MultiValue object instead of a plain hashref, but by the time
this callback is invoked it is too late and the dupes are gone.
It would be useful to be able to specify an "object provider" callback
for the JSON parser, something like
sub make_multihash {
tie my %mhash, 'Tie::Hash::MultiValue';
return \%mhash;
}
my $parsed = JSON->new
->object_provider(\&make_multihash)
->parse('{"foo":1, "foo":2, "bar":{"a":1, "b":2,
"b":3}}');
and then both $parsed and $parsed->{bar} are actually blessed objects
and the multiple values are saved (hoorah!). It would work in general
for any object_provider callback that returned a tied hashref, e.g.
Tie::Hash::Indexed, Tie::Hash::SortedHash, Tie::StoredOrderHash (ahem)
What do you think?