in reply to JSON and Perl Objects - How to access data?
The structure is a hashref that contains a single member with key "items" which consists of an arrayref that contains two hashrefs. So you have to dereference the arrayref to get its members something like this:
To change the data:for my $item( @{$inventors_object->{items}} ){ print $item->{name} . "\n"; };
To turn it back into a JSON string:$inventors_object->{items}->[0}->{name} = 'new name';
update here is your mistake:my $new_json = objToJson( $inventors_object );
You are trying to turn an arrayref into an array without dereferencing it. Instead you want:@inventors_array = $inventors_obj->{"items"};
@inventors_array = @{ $inventors_obj->{"items"} };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: JSON and Perl Objects - How to access data?
by Anonymous Monk on Jun 02, 2010 at 18:52 UTC | |
Re^2: JSON and Perl Objects - How to access data?
by Anonymous Monk on Sep 05, 2015 at 15:57 UTC | |
by 1nickt (Canon) on Sep 05, 2015 at 17:40 UTC | |
by Anonymous Monk on Sep 06, 2015 at 04:35 UTC | |
by AnomalousMonk (Archbishop) on Sep 06, 2015 at 13:04 UTC | |
by Anonymous Monk on May 25, 2018 at 00:37 UTC | |
by poj (Abbot) on Sep 05, 2015 at 16:39 UTC |
In Section
Seekers of Perl Wisdom