Here below is an example on changing a property name.
var Scrubber = require('object-scrubber'); var testObj = { } var scrubber = new Scrubber() scrubber.when(function (x) { return x.parent && x.key === '_id' }, function (x) { // set the value to a new property in the parent x.parent.id = x.value // delete the previous property delete x.parent._id // change to the new key for the next processors to find x.key = 'id' // scrub the new value for other processors to process return x.scrub(x.parent.id) }); scrubber.scrub(testObj);