Registry / devops / json-schema-defaults

json-schema-defaults

JSON →
library0.4.0jsnpmunverified

Generates a plain JSON object from the default values defined in a JSON Schema. Version 0.4.0 is the latest stable release (final release from 2015, now unmaintained). Supports both Node.js and browser environments, including CommonJS, AMD, and standalone script tag usage. Also provides a CLI tool. This package is a simple utility for extracting default values from schemas and does not support JSON Schema draft-07+ features like const, if/then/else, or complex defaults. It works with basic default values only (no recursive objects). The package has no dependencies and is very small (~1KB minified).

npm install json-schema-defaults
INSTALL
IMPORT
SIG · JSON-SCHEMA-DEFAUL
J
json-schema-defaults
devopsjavascriptv0.4.0
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.

defaults
var defaults = require('json-schema-defaults');
import defaults from 'json-schema-defaults';
CommonJS only; no ESM. ES import syntax will fail.
jsonSchemaDefaults
window.jsonSchemaDefaults({...})
window.jsonSchemaDefaults({...})
Standalone browser global. Also available as noConflict() if needed.
defaults (AMD)
define(['defaults'], function(defaults) { ... });
define(['json-schema-defaults'], function(defaults) { ... });
AMD path must be configured as 'defaults' pointing to lib/defaults.js.

Basic usage showing extraction of default values from a JSON Schema object.

var defaults = require('json-schema-defaults'); var schema = { type: 'object', properties: { name: { type: 'string', default: 'John Doe' }, age: { type: 'integer', default: 30 }, active: { type: 'boolean', default: true } } }; var result = defaults(schema); console.log(result); // { name: 'John Doe', age: 30, active: true }
Debug
Known issues
deprecatedPackage is unmaintained since 2015. No support for newer JSON Schema drafts.
fix
Consider using @json-schema-tools/defaults or ajv defaults for modern schema support.
affects: >=0.0
gotchaDoes not process nested objects or arrays recursively; only top-level defaults are extracted.
fix
Manually handle nested schemas or use a recursive solution.
affects: >=0.0 <1.0
gotchaOnly copies the 'default' keyword; ignores other schema constraints like 'const' or 'enum'.
fix
Use a more comprehensive schema processing library.
affects: >=0.0 <1.0
gotchaCLI tool prints output to stdout; if using in CI, ensure output is captured correctly.
fix
Redirect stdout as needed, e.g., json-schema-defaults schema.json > output.json
affects: >=0.0 <1.0
Errors
Common errors & fixes
Error: Cannot find module 'json-schema-defaults'
Module not installed or not found in node_modules.
fix
Run npm install json-schema-defaults and ensure correct require path.
ReferenceError: require is not defined
Using CommonJS require in a browser environment without bundler.
fix
Use the standalone script tag instead: <script src='lib/defaults.js'></script>
defaults is not a function
Using ES6 import style (import defaults from ...) which is not supported.
fix
Use const defaults = require('json-schema-defaults'); in Node or use the global window.jsonSchemaDefaults in browser.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
json-schema-defaults — npm install json-schema-defaults · libregistry