Is there a way to save the "path" of a json object to a variable? That is, if I have something like this:
var obj = {"Mattress": {
"productDelivered": "Arranged by Retailer",
"productAge": {
"year": "0",
"month": "6"
}
}
};
How can I loop through and save each key node name to a variable? eg. (I need it in this format): Mattress[productDelivered], Mattress[productAge][year], Mattress[productAge][month]
I have got partly there in this fiddle http://jsfiddle.net/4cEwf/ but as you can see in the log, year and month don't get separated but append to the array as well. I know this is because of the looping I have going on but I'm stuck on how to progress to get the data format I require. The flow I have set up in the fiddle is emulating what I need.
Is there a way I haven't considered to do this?