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.

#!/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;

Open in new window


returns the below in kpi_dashboard_data_1hr.json
[{"testcase1_count":"1773"}][{"testcase2_count":"0"}]

Open in new window


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?
DalexanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FishMongerCommented:
I have not done any testing, but my first though would be to push them onto an array then strip off the outer brackets and use a join statement when outputting to the file.
$obj->do_select($testcase1_count, "testcase1_count", 1);
push @jason, $obj->get_json;

$obj->do_select($testcase2_count, "testcase2_count", 1);
push @jason, $obj->get_json;

s/^\[|\]$//g for @jason;

print '[' . join(',', @jason) . ']';

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.