I have a json structure loaded on to a hash, like this:
my $data = {
"store1" => {
"book" => [
{ "category" => "reference",
"author" => "Nigel Rees",
"title" => "Sayings of the Century",
"price" => 8.95,
},
{ "category" => "fiction",
"author" => "Herman Melville",
"title" => "Moby Dick",
"isbn" => "0-553-21311-3",
"price" => 8.99,
},
],
"bicycle" => [
{ "color" => "red",
"price" => 19.95,
},
],
},
"store2" => {
"book" => [
{ "category" => "reference",
"author" => "Nigel Rees",
"title" => "Sayings of the Century",
"price" => 8.95,
},
{ "category" => "fiction",
"author" => "Herman Melville",
"title" => "Moby Dick",
"isbn" => "0-553-21311-3",
"price" => 8.99,
},
],
"bicycle" => [
{ "color" => "red",
"price" => 19.95,
},
],
},
};
Tools like JSON::Path, return the values of the elements matching the path.
my $jpath = JSON::Path->new('$.*.book[*]');
my @books = $jpath->values($data);
I would like to get the Paths, not the values. Something like:
[
'$->{store}{book}[0]',
'$->{store}{book}[1]',
'$->{store}{book}[2]'
]
I want to find information in the Path, in order to know the location of the results and not the results themselves. For example, given the query:
my $jpath = JSON::Path->new('$.*.book[*]');
I would like to know if the Path contains "store1" or "store2", so I need the query to return the Paths.
Is there a way to do this?
Thanx, Spiros