I have a JSON object, which includes other objects and list of objects. Have to write a function, which iterates through all properties of objects as well as object within object and list of objects and replace null
with an empty string.
As it is loop inside loop, I need to implement deferred so sequential processing. I tried many ways, but failed. Anyone please help.
function ValidateObject(result) {
var aObj = result.A;
aObj = VerifyForNull(aoBJ);
var bObj = result.B;
bObj = VerifyForNull(bObJ);
for (var i = 0; i < result.C.length; i++) {
var cObj = result.C[i];
cObj = VerifyForNull(cObJ);
for (var j = 0; j < cObj.D.length; j++) {
var dObj = cObj.D[i];
dObj = VerifyForNull(dObj);
}
}
}
function VerifyForNull(obj) {
Object.keys(obj).forEach(function(key) {
var val = obj[key];
if (val == null || value === undefined) {
obj[key] = "";
}
});
}