12345678910111213141516171819202122232425262728293031 |
- #!/usr/bin/env perl
- # License: CC0
- use warnings;
- use strict;
- use Data::Dumper;
- # To install JSON::Tiny:
- # $ cpanm -n JSON::Tiny || cpan -T JSON::Tiny
- use JSON::Tiny qw(decode_json);
- sub read_json {
- my $json_filepath = shift;
- open( my $json_file, "<", "$json_filepath" ) or die("File $json_filepath not found");
- $/ = undef;
- my $json = <$json_file>;
- close($json_file);
- return decode_json( $json );
- }
- my $hash = read_json('info.json');
- print "-- Below are cars:\n";
- print Dumper($hash->{cars});
- print "-- Below are people:\n";
- foreach my $person (@{$hash->{people}}) {
- print Dumper($person);
- }
|