2

I'm trying to do something that seems to be very simple, but I can't figure out how to do it in Perl : I want to output a JSON-formatted array of hashes.

The array of hashes in question is actually an array of DBIx::MyParse Items object instances. Here is my code :

use strict;
use DBIx::MyParse;
use JSON::PP;
my $json = JSON::PP->new->ascii->pretty->allow_nonref;

our $parser = DBIx::MyParse->new( database => "test", datadir => "/tmp/myparse" );
our $query = $parser->parse("UPDATE table1 SET field1 = 1;");

$json->convert_blessed(1);
print $json->encode(@{$query} );

And this is what this script outputs :

"SQLCOM_UPDATE"

Which is actually the first element of the array that I want to output as a whole. Here is the content of the array that I see when I step-by-step debug the script : Query debug value

I would like to have the whole structure in my JSON output. How can I achieve this ?

1 Answer 1

5

JSON::encode just expects a single argument, not a list. Use $json->encode( $query ).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.