oferei / json-gate

A friendly, fast JSON schema validator
MIT License
100 stars 16 forks source link

Clear object using new form to additionalProperties #27

Closed andersonba closed 1 year ago

andersonba commented 10 years ago

This feature remove all non-matching properties from original JSON object.

How to use: additionalProperties: 'remove'

See bellow:

// Schema
{
   str: { type: 'string' },
   additionalProperties: 'remove'
}
// Object
{
   str: 'hi',
   extra: 'unimportant data, discard this',
   extra1: 'discard this'
}
// Result object (after validate):
{
   str: 'hi'
}
// Getting result object
newObject = schema.validate(Object);

// or
schema.validate(Object, function(err, obj) {
   newObject = obj;
});

Obs.: I moved to new branch, because I needed merge my features in master.