Registry / storage / json-schema-filter

json-schema-filter

JSON →
library0.1.5jsnpmunverified

Filters objects from a JSON document based on a JSON Schema, removing properties not defined in the schema. Version 0.1.5 is the latest. It recursively processes nested objects and arrays, but does not validate against the schema; for validation use a separate tool like JSV. Designed for performance when the schema is smaller than the document. Typically used for cleaning up JSON data by stripping unknown fields.

npm install json-schema-filter
INSTALL
IMPORT
SIG · JSON-SCHEMA-FILTER
J
json-schema-filter
storagejavascriptv0.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const filter = require('json-schema-filter');
import filter from 'json-schema-filter';
The package is CommonJS only; no ES module or TypeScript support.

Shows filtering a simple object using a schema, removing properties not in the schema.

const filter = require('json-schema-filter'); const schema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer' } }, required: ['name'] }; const document = { name: 'Alice', age: 30, extra: 'remove me' }; const filtered = filter(schema, document); console.log(filtered); // { name: 'Alice', age: 30 }
Debug
Known issues
gotchaProperties defined in the schema but not present in the document are omitted from output (not set to null or undefined).
fix
Ensure your schema does not list properties you expect to always be present unless you handle missing keys separately.
affects: >=0.0.0
gotchaObjects with type 'object' but no 'properties' in schema are removed entirely, even if they have data.
fix
Define all properties explicitly in the schema to preserve them.
affects: >=0.0.0
gotchaThis package does not validate data; it only filters by schema. Use a validator like AJV for validation.
fix
After filtering, run your data through a JSON Schema validator if you need validation.
affects: >=0.0.0
gotchaArrays with 'additionalItems: false' are not fully supported; only the 'items' schema is used for each element.
fix
Ensure your schema uses 'items' for all array elements; additional items will be kept.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: filter is not a function
Using ES module import incorrectly on a CommonJS module.
fix
Use require('json-schema-filter') instead of import.
Cannot read property 'type' of undefined
Passing a schema with missing 'type' at root or nested properties.
fix
Ensure the schema object has a 'type' field at every level where you want filtering.
filter(...) returns null when schema has no properties
A schema with 'type: object' but no 'properties' results in the entire object being removed.
fix
Define at least one property in the schema to keep the object.
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
json-schema-filter — npm install json-schema-filter · libregistry