
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
json-schema-strip-unknown
Advanced tools
Strips unknown values from a json-schema (forked from json-schema-filter to fix bugs)
#json-schema-filter
Filters (removes) objects recursively from document based on passed json-schema
Note that this does NOT validate your document against the schema, use something like JSV npm after calling.
For performance reasons it is assumed that the json-schema contains less items then the document, that is you are going to be removing from the document in most or all cases, if not I would recommend another solution which bases its recursive evaluation on the document instead.
$ npm install json-schema-filter
var filter = require('json-schema-filter');
var schema = {
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
},
"general": {
"type": "object",
"required": false
},
"contacts": {
"type": "array",
"id": "http://jsonschema.net/contacts",
"required": false,
"items": {
"type": "object",
"id": "http://jsonschema.net/contacts/0",
"required": false,
"properties": {
"phone": {
"type": "string",
"required": false
}
}
}
},
"hobbies":{
"type": "array",
"required": false,
"items": {
"type": "string"
}
}
},
"required": ["firstName", "lastName"]
};
var document = {firstName: 'John', lastName: 'Dow!', shouldNot: 'see this!'};
var results = filter(schema, document);
console.log(results); // # {firstName: 'John', lastName: 'Dow!'}
// Works on nested objects and arrays as well...
var document2 = {
firstName: 'Johnny',
lastName: 'Dowsky',
contacts: [
{phone: '303943', shouldNot: 'see this!'},
{phone: '399494'}
]
}
var nestedResults = filter(schema, document2);
console.log(nestedResults); // # {firstName: 'Johnny', lastName: 'Dowski', contacts: [{phone: '303943', phone: '399494'}]}
If a "type": "object" with no "property": is defined (see 'general:' in above example), or empty, the entire object is removed from the results. It could be that you require it to be included but empty, but to the best of my knowledge I thought it would be cleaner to simply remove it if empty. Else it copies everything over, as in all of what is in the properties of the key.
Background info: The lack of property is legal in json-schema and means anything goes, or what I refer to as free-form.. free-style.. oh well, pick your meaning for it, it has the word 'free'!
FAQs
Strips unknown values from a json-schema (forked from json-schema-filter to fix bugs)
We found that json-schema-strip-unknown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.