I am working on a JSON data of shape as below.Its a list of documents and i am showing the first one
info=[
{id: 34,
log:[
{ttp : 80,
segm :[
{
dr: '2 hours'
room: 'F32'
},
{
dr: '48 hours',
room: 'G45'
}
],
},
{
ttp : 45,
segm:[
{
dr: '4 hours'
room: 'F32'
},
{
dr: '8 hours',
room: 'G45'
}
]
}
]
},
{document},
{document}
]
I have created this very simple document just for understanding of data structure.
Now the problem is i want to access dr and room which are in segm. To access them i am using three nested loops first loop to iterate over info. Second loop to iterate over log and third loop on segm.
for loop -> info -> for loop-> log -> for loop -> segm
But i am compromising on performance here as the data is growing it's becoming slower. I need a better solution (an optimized solution) for this that does not depend upon the data size. Also If we can avoid loops that would be better i think.