Registry / devops / async-json-schema-traverse

async-json-schema-traverse

JSON →
library1.0.1jsnpmunverified

Async version of json-schema-traverse that iterates over all schema objects in a JSON Schema document, invoking a callback (or pre/post callbacks) for each object. Version 1.0.1 supports both CommonJS and ESM, ships TypeScript types, and is a maintained fork of json-schema-traverse with async/await support. Key differentiator: works with promises for asynchronous traversal, while the original is synchronous. Suitable for JSON Schema processing pipelines that require async operations.

npm install async-json-schema-traverse
INSTALL
IMPORT
SIG · ASYNC-JSON-SCHEMA-
A
async-json-schema-traverse
devopsjavascriptv1.0.1
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
import traverse from 'async-json-schema-traverse'
const { traverse } = require('async-json-schema-traverse')
The package exports a single function as default. Named import will fail.
traverse (CJS)
const traverse = require('async-json-schema-traverse')
const { default: traverse } = require('async-json-schema-traverse')
In CommonJS, the default export is assigned to module.exports, so direct require works.
TypeScript types
import traverse from 'async-json-schema-traverse'
TypeScript types are bundled; no separate @types package needed.

Demonstrates traversing a JSON Schema with async/await, both single callback and pre/post callbacks.

import traverse from 'async-json-schema-traverse'; const schema = { type: 'object', properties: { foo: { type: 'string' }, bar: { type: 'integer' } } }; // With a single callback await traverse(schema, { cb: (schema, pointer, root, parentPointer, parentKeyword, parentSchema, key) => { console.log('schema:', JSON.stringify(schema), 'pointer:', pointer); } }); // With pre/post callbacks await traverse(schema, { cb: { pre: (schema, pointer, root) => { console.log('pre:', pointer); }, post: (schema, pointer, root) => { console.log('post:', pointer); } } });
Debug
Known issues
gotchaThe package does not resolve $ref references; schemas are passed as-is.
fix
Use a separate JSON Schema resolver (e.g., ajv) if you need $ref resolution.
affects: >=0.0.0
gotchaBoolean schemas (draft-06+) are not traversed; they are skipped.
fix
Check schema type before traversal; boolean schemas are not passed to callback.
affects: >=1.0.0
gotchaThe callback parameter order is: schema, JSON pointer, root schema, parent pointer, parent keyword, parent schema, index/property.
fix
Use named parameters or destructure carefully to avoid confusion.
affects: >=0.0.0
gotchaWhen using pre/post callbacks, both must be provided as an object with 'pre' and 'post' keys.
fix
Provide an object: { pre: preCallback, post: postCallback }.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: traverse is not a function
Using named import instead of default.
fix
Use import traverse from 'async-json-schema-traverse' or const traverse = require('async-json-schema-traverse')
Cannot find module 'async-json-schema-traverse' or its corresponding type declarations.
Missing package installation or TypeScript type configuration.
fix
npm install async-json-schema-traverse (types are bundled). Ensure tsconfig.json includes 'node' module resolution.
cb is not a function
Passed an object without 'cb' property or malformed callbacks.
fix
Provide cb: callbackFunction or cb: { pre: preFn, post: postFn }
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources