Subject: | 0th element of an array not returned |
If you have a path addressing the 0th element of an array, the whole
array is returned. e.g. if you do:
my $data = {
'foo' => [
{
'bar' => 1,
},
{
'bar' => 2,
},
{
'bar' => 3,
},
]
};
my $jpath1 = JSON::Path->new('$.foo[0]');
my @values = $jpath1->values($data);
@values will then contain all the array elements, instead of the first
(i.e. the 0th).
I think the fix is to change the second line of the trace sub to:
return $self->store($path, $val) if $expr eq '';
The problem is $expr is 0 when trying to find the 0th element, so the
expression currently returns true, when it still has further to walk
down the structure.