I have an API response of the following structure
{
"id": "123342-123412",
"data": [
{
"id": "ace123",
"name": "Tom",
"files": [
{
"color": "yellow",
"file_id": "245"
},
{
"color": "red",
"file_id": "233"
}
]
},
{
"id": "asd123",
"name": "Jerry",
"files": [
{
"color": "red",
"file_id": "210"
},
{
"color": "green",
"file_id": "221"
}
]
},
{
"id": "acs123",
"name": "Barbie",
"files": [
{
"color": "green",
"file_id": "201"
}
]
}
]
}
I am new to ruby, I want to filter out all file ids with the color red, what's the better way of doing it rather than iterating through the whole JSON using
data.each do | object|
# individual element search code
end
I am using ruby version 2.6
question from:
https://stackoverflow.com/questions/65875451/filtering-a-nested-json-for-a-particular-flied-and-returning-adjacent-member-in 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…