Dalexan
asked on
PERL export multiple query results to a JSON file
I'm trying to export multiple query results to a json file, the below code exports the results of the querys to a single json file but since Its two separate print statements the json is not correct. ][ separates the query results in the json file.
returns the below in kpi_dashboard_data_1hr.jso n
I'm assuming I could use a SED statement in the perl to replace the ][ with a comma in the json file but there has to be a better way?
#!/usr/bin/perl -w
use DBIx::JSON;
use strict;
my $driver = "mysql";
my $database = "testdb";
my $dsn = "dbname=$database;host=192.168.1.1;port=3306";
my $userid = "test";
my $password = "password";
my $testcase1_count = "SELECT COUNT(odi_id) as testcase1_count from Orders.order_item oi inner join Orders.order_header oh ON oi.ord_id=oh.ord_id
where oh.ord_status_id<>'X' ";
my $testcase2_count = "SELECT COUNT(odi_id) as testcase2_count from Orders.order_item oi inner join Orders.order_header oh ON oi.ord_id=oh.ord_id
where oh.ord_status_id<>'R' ";
open STDOUT, '>', "/var/www/test/data/kpi_dashboard_data_1hr.json";
my $obj = DBIx::JSON->new($dsn, "mysql", $userid, $password);
$obj->do_select($testcase1_count, "testcase1_count", 1);
print $obj->get_json;
$obj->do_select($testcase2_count, "testcase2_count", 1);
print $obj->get_json;
$obj->err && die $obj->errstr;
returns the below in kpi_dashboard_data_1hr.jso
[{"testcase1_count":"1773"}][{"testcase2_count":"0"}]
I'm assuming I could use a SED statement in the perl to replace the ][ with a comma in the json file but there has to be a better way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.