Registry / testing / metalsmith-json-schema

metalsmith-json-schema

JSON →
library1.2.2jsnpmunverified

Metalsmith plugin for validating metadata against JSON Schema. Version 1.2.2, stable with low release cadence. It integrates schema validation into the Metalsmith build pipeline, ensuring metadata conforms to defined schemas. Alternative to manual validation, leveraging standard JSON Schema (draft 4/7).

npm install metalsmith-json-schema
INSTALL
IMPORT
SIG · METALSMITH-JSON-SC
M
metalsmith-json-schema
testingjavascriptv1.2.2
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.

plugin
import { plugin } from 'metalsmith-json-schema'
const plugin = require('metalsmith-json-schema')
Default export is a function; use default import if using ES modules. The plugin is a metalsmith plugin function.
Metalsmith
import Metalsmith from 'metalsmith'
This plugin pairs with Metalsmith, which is a separate dependency.
plugin
const plugin = require('metalsmith-json-schema').plugin
const plugin = require('metalsmith-json-schema')
In CommonJS, the named export 'plugin' must be accessed if not using default. The package has both default and named export.

Demonstrates initializing Metalsmith with json-schema plugin, specifying schema files in glob pattern, and enabling strict validation.

import Metalsmith from 'metalsmith'; import plugin from 'metalsmith-json-schema'; Metalsmith(__dirname) .use(plugin({ schemas: 'schemas/*.json', allowUnknown: false, throwOnError: true })) .build((err) => { if (err) throw err; console.log('Build complete!'); });
Debug
Known issues
gotchaPlugin validates metadata at the end of the build, not per-file. Errors may only surface after all files processed.
fix
Use per-file validation plugins if you need early error detection.
affects: >=1.0.0
deprecatedThe 'use' function signature changed in v2.0.0 to accept a single object argument instead of multiple.
fix
Pass all options as a single object: .use(plugin({ schemas: '...' }))
affects: >=2.0.0
breakingDefault export changed from a factory function to the plugin function itself in v2.0.0.
fix
Update imports: import plugin from 'metalsmith-json-schema' (no factory call).
affects: >=2.0.0
gotchaSchema file paths are relative to Metalsmith source directory, not project root.
fix
Use absolute paths or ensure relative paths are correct from the source.
affects: >=1.0.0
Errors
Common errors & fixes
metalsmith-json-schema: Cannot find module 'glob'
Optional peer dependency 'glob' not installed.
fix
Install glob: npm install glob
metalsmith-json-schema: schema validation failed: [object Object]
Validation error with schema mismatch, but error is not descriptive.
fix
Enable verbose logging to see detailed error messages.
TypeError: plugin is not a function
Incorrect import: trying to call default export as factory.
fix
Use correct import: import plugin from 'metalsmith-json-schema'; then use it as .use(plugin(...))
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
ajvrequiredJSON Schema validation engine
globrequiredFile pattern matching for schema files
Agent activity
6 hits · last 30 days
node
6
Resources
metalsmith-json-schema — npm install metalsmith-json-schema · libregistry