json-schema-traverse
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Json-schema-traverse is a powerful tool used to traverse a JSON schema, where each schema object is passed to a callback function. Its primary function is to navigate through a JSON schema object and execute provided callback functions on each schema object, providing rich and granular control over the operations you might want to perform on each object.
The json-schema-traverse npm package can be incorporated into your JavaScript project in a few simple steps. First, you install the package using npm in your terminal: npm install json-schema-traverse
.
Post installation, you can then require and use json-schema-traverse in your JavaScript code. Here's a basic usage example:
const traverse = require('json-schema-traverse');
const schema = {
properties: {
foo: {type: 'string'},
bar: {type: 'integer'}
}
};
let cb = function(schema, pointer, rootSchema, parentPointer, parentKeyword, parentSchema, indexOrProp){
console.log(schema);
};
traverse(schema, {cb});
// the callback function 'cb' is triggered for each schema object
In this sample code, traverse
is called with the schema
and an object that contains your callback function cb
. This cb
function serves as your custom logic that will be applied to each schema object during traversal.
Documentation for json-schema-traverse is primarily available on its npm package page (https://www.npmjs.com/package/json-schema-traverse) and the GitHub repository (https://github.com/epoberezkin/json-schema-traverse). Here you will find in-depth details about how the package works, usage examples, traverse options, and more. All the information required to understand the functioning of the package can be found on these pages.