Just create a Perl structure corresponding to the expected JSON and use the JSON module to encode it to JSON. (Update: your expected structure is missing two commas).
#!/usr/bin/perl
use warnings;
use strict;
use JSON;
my $struct = {
time => time,
id => int rand 65536,
};
while (<DATA>) {
chomp;
my ($key, $value, $format, $version) = split /,/;
push @{ $struct->{data} }, {
key => $key,
value => $value,
format => $format,
version => $version,
};
}
my $jsonizer = JSON->new->pretty;
print $jsonizer->encode($struct);
__DATA__
first,1,1.5.6,5.4
two,2,1.4.6,5.4
five,5,1.5.9,5.1
You might need to use JSON::XS or Cpanel::JSON::XS if speed is important to you.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,