Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t0019/parse_json.perl # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t0019 / parse_json.perl` 55 lines ยท 1061 bytes Raw Blame History 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 use JSON; 5 6 sub dump_array { 7 my ($label_in, $ary_ref) = @_; 8 my @ary = @$ary_ref; 9 10 for ( my $i = 0; $i <= $#{ $ary_ref }; $i++ ) 11 { 12 my $label = "$label_in\[$i\]"; 13 dump_item($label, $ary[$i]); 14 } 15 } 16 17 sub dump_hash { 18 my ($label_in, $obj_ref) = @_; 19 my %obj = %$obj_ref; 20 21 foreach my $k (sort keys %obj) { 22 my $label = (length($label_in) > 0) ? "$label_in.$k" : "$k"; 23 my $value = $obj{$k}; 24 25 dump_item($label, $value); 26 } 27 } 28 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"; 44 } 45 } 46 47 my $row = 0; 48 while (<>) { 49 my $data = decode_json( $_ ); 50 my $label = "row[$row]"; 51 52 dump_hash($label, $data); 53 $row++; 54 } 55