in reply to Returning data
"items" is a hash key which has a value that is a reference to an array of anon hashes.use strict; use warnings; use 5.10.0; use JSON; use Data::Dump qw(pp); my %output; foreach my $title ("Valls", "AUT15605", "10UT15605") { push @{$output{items}}, {title => $title}; } my $output_json = encode_json \%output; say $output_json; pp \%output; __END__ This is what the Perl structure looks like: { items => [ { title => "Valls" }, { title => "AUT15605" }, { title => "10UT15605" }, ], } This is the encoded JSON: {"items":[{"title":"Valls"},{"title":"AUT15605"},{"title":"10UT15605"} +]}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Returning data
by frank1 (Monk) on Apr 21, 2024 at 12:33 UTC |