Similar to Ramda: How to remove keys in objects with empty values? but I am looking for something that works recursively. This is so I can workaround a "feature" of AJV and JSON Schema where null !== undefined
.
I started with this... which is to remove the nulls but does not work recursively
import R from 'ramda';
describe('filter null values', () => {
it('should filter out null values', () => {
const specimen = {
tasks: [
{ id: 'foo', blank: '', zero: 0, nool: null },
{ nool: null },
{ id: '', blank: null, zero: 0, nool: null },
],
useless: { nool: null },
uselessArray: [{ nool: null }],
nool: null,
};
const expectation = {
tasks: [
{ id: 'foo', blank: '', zero: 0 },
{ id: '', zero: 0 },
],
};
const removeNulls = R.reject(R.equals(null));
expect(removeNulls(specimen)).toEqual(expectation);
});
});