json-schema-filter
json-schema-filter copied to clipboard
Keys with null values are always omitted
Hey
I am using this module to whitelist keys that can be exposed by API. IMHO the filter should not omit key-value pairs that have null
as value. As the current behavior is in place it cannot be changed. But maybe we could make a third parameter for the filter method where you could switch on/off null values omitting?
My suggestion would be to have a general property for allowing all null values. And possibility to switch separately for every type
.
var result = filter(schema, document, {
allowNulls: true
// or
allowNulls: ['boolean', 'number', 'integer', 'object', 'array', 'string', 'other']
})
Would it be considerable? PR?
BR
I would argue that it does not need allowNulls switch, null can be a perfectly valid value (schema allowing) and should never be removed if present. I consider current behaviour a bug. (BTW I am not complaining, we all write bugs occasionally)
I'm with allowing nulls, some documents might want to include the property in every case yet define it as null when nothing is available. So ya, anyone with a fix on this?