If I have some json like this:
{
"dcf93893d83e4f28953f140b9cba1963":{
"foo":{
"client":"127.0.0.1",
"id":"31971",
"start time":1654131724.160335
},
"bar":{
"client":"127.0.0.1",
"id":"23456",
"start time":1654131900.997766
}
}
}
I figured out how to loop through it like this:
for (var key in json) {
if (json.hasOwnProperty(key)) {
console.log(json[key])
}
}
How can I loop through each sub element (foo and bar in this case) and then fetch a key, for example id?
client, id and start time are the only known key names
Expected output:
31971
23456
EDIT: The json comes from fetch:
setInterval(function () {
fetch(<url>)
.then(function (response) {
return response.json();
})
.then(function (json) {
for (var key in json) {
if (json.hasOwnProperty(key)) {
console.log(json[key])
}
}
})
}, 2000);