JSFiddle - React, Tailwind, and code Playground
by Ajith S Punalur
HTML
<div id="json">dd</div>
JavaScript
function cleanJSON (jsonOb) {
$(jsonOb).each(function(i, el){
var key;
//console.log(el);
for (key in el) {
var v = el[key];
//console.log(key ,': ', v);
if(v === null || v==='null' || v === ''){
delete el[key];
}
//console.log(el);
}
jsonOb[i] = el;
});
return jsonOb;
}
$(document).ready(function(){
var myData = [
{
"id":"1",
"name": "Abc",
"age": 14
},
{
"id":"2",
"name": "Bbc",
"age": null
},
{
"id":"3",
"name": "Cbc",
"age": 21
},
{
"id":"4",
"name": null,
"age": 21
}
];
var cleanData = cleanJSON (myData);
console.log('myDat', myData);
$('#json').html(JSON.stringify(cleanData, null, 2))
console.log('CLean' + JSON.stringify(cleanData, null, 2));
});