After retrieving a JSON such as this:
"JSON": [
{
"mySchool": "college",
"myHome": "apartment",
"myFavoriteSport": "soccer"
},
{
"mySchool": "highschool",
"myHome": "house",
"myFavoriteSport": "hockey"
},
{
"mySchool": "college",
"myHome": "box",
"myFavoriteSport": "soccer"
},
{
"mySchool": "elementary",
"myHome": "tent",
"myFavoriteSport": "soccer"
}
]
How could I filter it conditionally so that... if soccer
is the value of myFavoriteSport
key, then return an array of all objects containing the myFavoriteSport: soccer
pair? I'm sure I'll end up pushing
the object into the array at the end, but I don't quite know how to single it out so that I can assign it to a variable.
I'm sure it will involve some type of loop, but this is my first time working with JSON and objects of this type so I'm a little unsure of how to approach it.