I want to stringify my json but I want to exclude empty nested arrays of objects.
My json looks likt this:
{
"Fe": {
"Fh": {
"a" : 1,
"b" : "foo"
},
"Fb": {
"Dbs": [
{
"Nl": "1",
"Dt": "red",
}
],
"Dr": [
{
}
]
}
}
I want to to ignore "Dr" because it is empty.
How can I do it in typescript/Javascript?
Here it the code that I have tried:
const str = JSON.stringify(this.json, replacer);
replacer(key, value) {
if (value === null || value === {})
return undefined;
else
return value;
};
Thanks