asynchronous - Looping through JSON with node.js -


i have json file need iterate over, shown below...

{     "device_id": "8020",     "data": [{         "timestamp": "04-29-11 05:22:39 pm",         "start_value":  0.02,         "abstract": 18.60,         "editor": 65.20     }, {         "timestamp": "04-29-11 04:22:39 pm",         "end_value":  22.22,         "text": 8.65,         "common": 1.10,         "editable": "true",         "insert": 6.0     }] } 

the keys in data not same (i've used examples, there 20 different keys), , such, cannot set script statically reference them values.

otherwise state

var value1 = json.data.timestamp; var value2 = json.data.start_value; var value3 = json.data.abstract; etc 

in past i've used simple foreach loop on data node...

foreach ($json->data $key => $val) {     switch($key) {         case 'timestamp':             //do this;         case: 'start_value':             //do     } } 

but don't want block script. ideas?

you can iterate through javascript objects way:

for(var attributename in myobject){     console.log(attributename+": "+myobject[attributename]); } 

myobject json.data


Comments