In my script to_json() converting loop_data in json format and assigning to $json.
my $json = to_json(\@loop_data);
print $json;
gives this output.
[
{
"Name": "Vivek",
"Age": 20
},
{
"Name": "Sonali",
"Age": 19
}
]
But instead of that i want print $json to give this output.
{"Friends" : [
{
"Name": "Vivek",
"Age": 20
},
{
"Name": "Sonali",
"Age": 19
}
]}
Where to add "Friends" and {}.
You could pass a reference to a hash with Friends
as the key and a reference to your array as the value:
my $json = to_json({"Friends" => \@loop_data});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With