Have been looking for a way to get both the key\value from a json string without having to build a new json string based on the pair.
Having the following example code: (I have modified code from Here)
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw(Dumper);
my $grades = {'PetiBar' => {
'Mathematics' => 82,
'Art' => 99,
'Literature' => 88
},
'FooBar' => {
'Mathematics' => 97,
'Literature' => 67
}
};
The result I'm looking after is:
'PetiBar' => {
'Mathematics' => 82,
'Art' => 99,
'Literature' => 88
}
This will give both objects, not only one:
foreach my $val ($grades) {
print Dumper $val;
}
This will only give me the values without the key:
foreach my $key (keys %{$grades}) {
print Dumper $grades->{$key};
}
How do I get both in a variable? Do I have to take the key and value, and build a new json string from them?
I have some running code here