matthewmueller / x-ray

The next web scraper. See through the <html> noise.
MIT License
5.87k stars 349 forks source link

Option to return null when empty #198

Closed Panthro closed 5 years ago

Panthro commented 8 years ago

Subject of the issue

Add an option to return null when empty for schema strict applications

Expected behaviour

When an element return empty, add the element as a null

Eg:

{
  "id":"0",
  "name":null
}
oskarjakiela commented 8 years ago

You can use filters as a workaround:

var Xray = require('x-ray');
var x = Xray({
  filters: {
    nullify: function(value) { return value.length ? value : null; }
  }
});

x('https://google.com', {
  empty: 'empty | nullify'
});
simonseddon commented 7 years ago

Having the same issue myself and tried a filter with no joy. Tried yours out of interest. No such luck. Have you tried this yourself with any luck?

lathropd commented 5 years ago

Dupe of #202. Merging.