json-schema-filter icon indicating copy to clipboard operation
json-schema-filter copied to clipboard

Keys with null values are always omitted

Open vellotis opened this issue 8 years ago • 2 comments

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

vellotis avatar Jun 15 '16 20:06 vellotis

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)

nicsnoek avatar Dec 16 '16 05:12 nicsnoek

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?

alank64 avatar Dec 20 '16 15:12 alank64