Convert-Pheno
view release on metacpan or search on metacpan
sub read_first_json_object {
my ($filename) = @_;
open my $fh, '<', $filename or die "Could not open '$filename': $!";
local $/; # Enable slurp mode to read the entire file
my $json_text = <$fh>;
close $fh;
# Decode the JSON text as an array
my $json_array = decode_json($json_text);
# Return the first element if the decoded JSON is an array
return
ref $json_array eq 'ARRAY'
? $json_array->[0]
: die "Expected a JSON array in $filename";
}
( run in 0.423 second using v1.01-cache-2.11-cpan-26ccb49234f )