Need help with checking if a specific path is present in a JSON object?
var data = {
"schemaOne": {
"name": "abc",
"Path": "i.abc",
"count": 5347,
"subFolders": [
]
},
"schemaTwo": {
"name": "cde",
"Path": "i.cde",
"count": 0,
"subFolders": [
{
"name": "efg",
"Path": "",
"count": 0,
"subFolders": [
]
},
{
"name": "hij",
"Path": "i.hij",
"count": 1,
"subFolders": [
]
}
]
}
}
var inputpath = "data.count";
I have found this code after researching that checks for the path o.Path
but I need to modify it to dynamically check if the path data.count
exists in the JSON object.
function updateData(obj, path, count) {
if (obj.Path == path) {
obj.count = count;
} else {
var array;
if (Array.isArray(obj)) array = obj;
else if (obj.subFolders) array = obj.subFolders;
else return;
for(var i=0; i < array.length; i++) {
updateData(array[i], path, count);
}
}
}