It is undefined because what you have in data.maps[x] is not an object, but a string. Since the string does not have a property called id , you get undefined . I would probably do something like this (if I could not modify the perl script):
var mapData = JSON.parse(data.maps[x]);
But the best thing to do is to make sure that it does not encode it as a string, but as the correct JSON.
This part in your perl script:
my $map = qq{{"id":"$id","name":"$name","date_created":"$date"}};
Just pops a row from all this data. Instead, what you want is the actual perl hash, which can be translated into a JSON map / associative array. So try the following:
my $map = { "id" => "$id", "name" => "$name", "date_created" => "$date" }; push $maps, $map;
That way, you really have a perl hash (not just a string) that will be translated into the correct JSON.
As an example, I wrote several test codes:
use strict; use JSON::XS; my $maps = []; push $maps, { id => 1, blah => 2 }; push $maps, { id => 3, blah => 2 }; my $j = JSON::XS->new->utf8->pretty(1); my $output = $j->encode({ success => "list of blah", maps => $maps }); print $output;
When you run this, you will get:
{ "success" : "list of blah", "maps" : [ { "blah" : 2, "id" : 1 }, { "blah" : 2, "id" : 3 } ] }