frank1 has asked for the wisdom of the Perl Monks concerning the following question:
how can i add a [ in my json message to be like this
[ { "id": 1, "location": "UAE", "name": "jake", "gender": "male" } ]
my script below outputs like this without [
{ "id": 1 "location": "UAE" "name": "jake" "gender": "male" }
my %hash; foreach my $result (@$result) { my ($id, $location, $name, $gender) = @$result; %hash = ( "id" => $id, "location" => $location, "name" => $name, " +gender" => $gender); push( @$result, \%hash ); } my $json = encode_json \%hash; print $CGI->header( -type => 'application/json' ),$json;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: formatting json message
by stevieb (Canon) on May 16, 2024 at 16:12 UTC | |
by frank1 (Monk) on May 16, 2024 at 16:30 UTC |