srchulo has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I am trying to build JSON such as this with Perl:
[{"name":"picture1.jpg","size":902604,"url":"\/\/example.org\/files\/picture1.jpg","thumbnail_url":"\/\/example.org\/thumbnails\/picture1.jpg","delete_url":"\/\/example.org\/upload-handler?file=picture1.jpg","delete_type":"DELETE"},{"name":"picture2.jpg","size":841946,"url":"\/\/example.org\/files\/picture2.jpg","thumbnail_url":"\/\/example.org\/thumbnails\/picture2.jpg","delete_url":"\/\/example.org\/upload-handler?file=picture2.jpg","delete_type":"DELETE"}]Essentially it is JSON array of JSON objects. However, I am not finding any good tutorials online. Does anyone have any suggestions? Currently I am using the JSON::XS module to decode, but I'm open to anything as long as it works.
Currently I have this code:
my %hash = {}; $hash{'lool'} = "WEEEE"; $hash{'YAY'} = "WEEEE"; my $json = JSON->new->allow_nonref; my $json_text = $json->encode(\%hash);
Only problem is that it creates this:
{"lool":"WEEEE","YAY":"WEEEE","HASH(0x8b8410)":null}Which also include the hash reference itself in it. Any help would be appreciated!
Many Thanks,
srchulo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Build JSON With Perl
by MVS (Monk) on Nov 11, 2011 at 07:16 UTC | |
by Tux (Canon) on Nov 11, 2011 at 07:20 UTC | |
|
Re: Build JSON With Perl
by Tux (Canon) on Nov 11, 2011 at 07:17 UTC |