Reputation: 577
I have some monotonous Json response in which I am trying access element of dictionary of array of dictionary of array using node.js but hard luck and unable to do so. I have tried accessing this stackoverflow solution https://stackoverflow.com/questions/30448517/node-js-how-to-access-values-of-dictionary-within-an-array-of-a-key-in-a-dicti
but in my case this is not working appropriately. My Json response is :
{
"client": [
{
"code": [
{
"id": "001",
"code": "100",
"type": "New"
},
{
"id": "002",
"code": "200",
"type": "Old"
}
]
}
]
}
From this response I want to get value of each "id", "code" and "Type". Any valuable answer would be appreciated. Thank you !!!
Upvotes: 0
Views: 994
Reputation: 2750
If your json was assigned to the variable x
x = {
"client": [
{
"code": [
{
"id": "001",
"code": "100",
"type": "New"
},
{
"id": "002",
"code": "200",
"type": "Old"
}
]
}
]
}
console.log(x["client"][0]["code"][0]["id"])
(I'll leave iterating through the arrays as an exercise for the reader)
Upvotes: 2