Given JSON String/object
{
"selectAll": false,
"include": {
"country_197": {
"id": "197",
"data_type": "country",
"name": "Singapore",
"desc": "",
"parent_key_id": "all_all",
"status": ""
},
"country_100": {
"id": "100",
"data_type": "country",
"name": "India",
"desc": "",
"parent_key_id": "all_all",
"status": ""
}
},
"exclude": {
"state_2": {
"id": "2",
"data_type": "state",
"name": "Andhra Pradesh",
"desc": "",
"parent_key_id": "country_100",
"status": ""
}
}
}
Given search string is: country_100
Required :
Have to search for country_100
in Given JSON String/object by key parent_key_id
Ex: searching country_100
is found :
{
"selectAll": false,
"include": {
"country_197": {
"id": "197",
"data_type": "country",
"name": "Singapore",
"desc": "",
"parent_key_id": "all_all",
"status": ""
},
"country_100": {
"id": "100",
"data_type": "country",
"name": "India",
"desc": "",
"parent_key_id": "all_all",
"status": ""
}
},
"exclude": {
"state_2": {
"id": "2",
"data_type": "state",
"name": "Andhra Pradesh",
"desc": "",
"parent_key_id": "**country_100**",
"status": ""
}
}
}
So return True, else return false.
This is what I have so far
var id = 'country_100', found = false;
for (var i=0; i<data.length; i++) {
console.log(data[i].exclude['state_2'].parent_key_id);
if (data[i].exclude['state_2'].parent_key_id == id) {
found = true;
break;
}
}