I want to print all the key value pairs of a JSON object. I don't know the keys of the object, so I am trying to get all the keys and corresponding values in a loop. But it appears that I am missing something obvious.
My perl code
%some_data = ("key1" => "value1","key2" => "value2","key3" => "value3","key4" => "value4");
my $json = encode_json \%some_data;
print $json; # it prints {"key2":"value2","key4":"value4","key1":"value1","key3":"value3"}
my simple javascript code
var jsonObj=$json;
var keys= Object.keys(jsonObj);
for (var i = 0; i < keys.length; i++){
document.write("<br /> ");
document.write(keys[i]);
// document.write(jsonObj.[keys[i]]); # doesnt work
}
document.write(jsonObj.key1); #works