I'm trying to iterate through an array of 'Machine' objects within a JSON file (sample object pasted below). Each object contains a nested array of software installed which I'd like to be able to search through dynamically via an input field. i.e. Identify a match between a user input string such as 'Unreal' and a machine that has the software installed where the name contains 'Unreal'.
I've already created the below algorithm to search through other objects in the top level of each JSON object, I assume it will be something similar but trial and error has not served me too well so far!
Simply adding value.software.product_name to retrieve each software name does not work considering the value is a level deeper in the object.
$.getJSON('../assets/mbid_directory.json', function(data){
$.each(data, function(key, value){
if(value.general.building_name.search(expression) != -1 || value.general.room_name.search(expression) != -1 || value.hardware.cpu.search(expression) != -1 ||
value.hardware.memory.search(expression) != -1 || value.hardware.gpu.search(expression) != -1 || value.hardware.screen_resolution.search(expression) != -1 ||
value.hardware.notable_peripherals.search(expression) != -1) {
//do something
}
})
})
{
"general": {
"machine_id": 2,
"machine_ip_address": "192.168.0.18",
"building_name": "Mellor",
"room_name": "S509",
"map_location": {
"lat": "-25.363",
"lng": "131.044"
}
},
"hardware": {
"cpu": "AMD Ryzen 5 3570K 3.40GHz",
"memory": "8GB DDR3 2600Ghz",
"gpu": "Nvidia GTX 790 Ti 3GB",
"screen_resolution": "1920x1200",
"notable_peripherals": "Dual-monitors"
},
"software": [
{
"product_title": "Windows 10 Education",
"product_version": "6.2.9200.16384"
},
{
"product_title": "Unreal Engine Games Studio",
"product_version": "8.4.2"
},
{
"product_title": "Microsoft Visual Studio 2017",
"product_version": "5.5.106.3"
}
]
},
Any guidance would be appreciated!