trace2: NULL is not allowed for va_list
[git/raj.git] / t / t0019 / parse_json.perl
blobfea87fb81b62d4f1e9612094c60ee8dceebc07be
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use JSON;
6 sub dump_array {
7 my ($label_in, $ary_ref) = @_;
8 my @ary = @$ary_ref;
10 for ( my $i = 0; $i <= $#{ $ary_ref }; $i++ )
12 my $label = "$label_in\[$i\]";
13 dump_item($label, $ary[$i]);
17 sub dump_hash {
18 my ($label_in, $obj_ref) = @_;
19 my %obj = %$obj_ref;
21 foreach my $k (sort keys %obj) {
22 my $label = (length($label_in) > 0) ? "$label_in.$k" : "$k";
23 my $value = $obj{$k};
25 dump_item($label, $value);
29 sub dump_item {
30 my ($label_in, $value) = @_;
31 if (ref($value) eq 'ARRAY') {
32 print "$label_in array\n";
33 dump_array($label_in, $value);
34 } elsif (ref($value) eq 'HASH') {
35 print "$label_in hash\n";
36 dump_hash($label_in, $value);
37 } elsif (ref $value) {
38 my $bool = $value ? 1 : 0;
39 print "$label_in $bool\n";
40 } elsif (defined $value) {
41 print "$label_in $value\n";
42 } else {
43 print "$label_in null\n";
47 my $row = 0;
48 while (<>) {
49 my $data = decode_json( $_ );
50 my $label = "row[$row]";
52 dump_hash($label, $data);
53 $row++;