use strict; use warnings; use DBI; use Data::Dumper; use JSON::XS; my $dbh = DBI->connect (q{DBI:ODBC:test}) or die $DBI::errstr; my $sth = $dbh-> prepare("SELECT val from buf WHERE dd_mm_yyyy= ? ") or die $dbh->errstr(); $sth->execute('2012-07-22 00:00:00') or die $dbh->errstr(); my $table; my $tbl_ary_ref; $tbl_ary_ref = $sth->fetchall_arrayref; if (defined $tbl_ary_ref){ $table->{date} = $tbl_ary_ref; } $tbl_ary_ref = encode_json $table; print qq{JSON-------------------JSON\n}; print $tbl_ary_ref."\n"; $sth->finish; $dbh->disconnect;