functionRemoveemptyfield (obj) {varNEWOBJ = {}; if(typeofobj = = "string") {obj=json.parse (obj); } if(objinstanceofArray) {NEWOBJ= []; } if(objinstanceofObject) { for(varattrinchobj) { if(Obj.hasownproperty (attr) && obj[attr]!== "" && Obj[attr]!==NULL&& Obj[attr]!==undefined) { if(Obj[attr]instanceofObject) {Newobj[attr]=Removeemptyfield (obj[attr]); }Else if(typeofOBJ[ATTR] = = "string" && ((Obj[attr].indexof ("{") >-1 && obj[attr].indexof ("}") >-1) | | (Obj[attr].indexof ("[") >-1 && obj[attr].indexof ("]") >-1))){ Try{ varAttrobj =Json.parse (obj[attr]); if(AttrobjinstanceofObject) {Newobj[attr]=Removeemptyfield (attrobj); } }Catch(e) {newobj[attr]=Obj[attr]; } }Else{newobj[attr]=Obj[attr]; } } } } returnNEWOBJ; }
Object-to-string removal of invalid fields
function Stringifynoemptyfield (obj) { var newObj = Removeemptyfield (obj); for (var in newObj) { ifinstanceof Array) { = json.stringify (newobj[attr]); } } return json.stringify (NEWOBJ); }
Removes a field with a value of NULL, Undefined, "" in the object