I want to be able to fetch data from a JSON file only if a value of a key matches that of an already stored variable in my script. For example, I have two stored variables:
- Weather, which has a value of hot.
- Distance, which has a value of 4.
I want to return only the objects in the JSON file that have these key value pairs and save the objects into an array. Any help would be much appreciated.
Heres my json file called 'locations.json':
[
{
"Distance ": 2,
"Weather": "cold"
},
{
"Distance ": 4,
"Weather": "hot"
},
{
"Distance ": 3,
"Weather": "cold"
},
{
"Distance ": 4,
"Weather": "hot"
}
]