Registry / devops / json-schema-from-path

json-schema-from-path

JSON →
library2.0.1jsnpmunverified

A utility to extract a sub-schema from a JSON Schema by traversing a path (using / or . separators). Version 2.0.1 is current. Supports properties, additionalProperties, patternProperties, and items. Returns null if no schema exists at path. Simple, no external dependencies. Lightweight alternative to full JSON Schema processors for path-based lookups.

npm install json-schema-from-path
INSTALL
IMPORT
SIG · JSON-SCHEMA-FROM-P
J
json-schema-from-path
devopsjavascriptv2.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.

getSchemaFromPath
const getSchemaFromPath = require('json-schema-from-path');
import getSchemaFromPath from 'json-schema-from-path';
This package does not provide ESM exports; using dynamic import may work but require is safe and documented.
default
import getSchemaFromPath from 'json-schema-from-path';
import { getSchemaFromPath } from 'json-schema-from-path';
Using named import will fail as the module exports a single function directly.
getSchemaFromPath
const { default: getSchemaFromPath } = await import('json-schema-from-path');
const getSchemaFromPath = await import('json-schema-from-path');
If using ESM dynamic import, the default export is under .default.

Demonstrates using require to import the function, defining a schema, and retrieving the sub-schema at path 'user/name'.

const getSchemaFromPath = require('json-schema-from-path'); const schema = { properties: { user: { properties: { name: { type: 'string' } } } } }; const path = 'user/name'; const subSchema = getSchemaFromPath(schema, path); console.log(subSchema); // { type: 'string' }
Debug
Known issues
gotchaPath order: The function traverses schema properties in the order they appear in the schema object. If properties are out of order, results may differ.
fix
Ensure properties are ordered as expected or use array paths consistently.
affects: >=1.0.0
gotchaNull return: Returns null if path doesn't exist, not undefined. Code must check for null explicitly.
fix
Use if (subSchema === null) to detect missing paths.
affects: >=1.0.0
gotchaSeparator confusion: Paths using '/' and '.' are both supported, but mixing them may cause unexpected traversal.
fix
Use only one separator consistently, e.g., always '/' or always '.'.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: getSchemaFromPath is not a function
Using ES6 import incorrectly or destructuring the default export.
fix
Use const getSchemaFromPath = require('json-schema-from-path'); or import getSchemaFromPath from 'json-schema-from-path';
Uncaught TypeError: Cannot read properties of undefined (reading 'properties')
Accessing sub-properties on null result when path not found.
fix
Check if getSchemaFromPath returns null before accessing properties.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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