Registry / devops / json-schema-migrate-x

json-schema-migrate-x

JSON →
library2.1.0jsnpmunverified

An actively maintained fork of json-schema-migrate for migrating JSON Schema between drafts: draft-04 to draft-07, draft-2019-09, or draft-2020-12. Version 2.1.0 ships TypeScript types, follows conventional commits, and uses Ajv under the hood. It replaces boolean exclusiveMinimum/Maximum with number form, converts single-value enum to const, replaces constant with const, empty schema with true, and schema {"not":{}} with false. draft2019 additionally splits dependencies into dependentRequired and dependentSchemas and handles $anchor. draft2020 converts array items to prefixItems.

npm install json-schema-migrate-x
INSTALL
IMPORT
SIG · JSON-SCHEMA-MIGRAT
J
json-schema-migrate-x
devopsjavascriptv2.1.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.

migrate (namespace import)
import * as migrate from 'json-schema-migrate-x'
import migrate from 'json-schema-migrate-x'
This package does not export a default; use namespace import.
draft7 (named import via namespace)
migrate.draft7(schema)
draft7(schema) // Not exported as named member; must use namespace.
Functions are properties of the namespace import.
migrate.getAjv
migrate.getAjv()
Returns the Ajv instance used internally; useful for error formatting.

Demonstrates namespace import and migration of a draft-04 schema to draft-07, draft-2019-09, or draft-2020-12.

import * as migrate from 'json-schema-migrate-x' const schema04 = { id: 'my-schema', minimum: 1, exclusiveMinimum: true } // Migrate to draft-07 migrate.draft7(schema04) console.log(schema04) // { // $id: 'my-schema', // exclusiveMinimum: 1 // } // Or draft-2019-09: const schema2019 = migrate.draft2019(schema04) console.log(schema2019) // Or draft-2020-12: const schema2020 = migrate.draft2020(schema04) console.log(schema2020)
Debug
Known issues
breakingPackage is a fork; imports and behavior differ from original json-schema-migrate.
fix
Use import * as migrate from 'json-schema-migrate-x' instead of the original package name.
affects: >=2.0.0
breakingNo default export; namespace import required.
fix
Use import * as migrate from 'json-schema-migrate-x'.
affects: >=2.0.0
deprecatedOriginal json-schema-migrate package is unmaintained; this fork is the recommended replacement.
fix
Switch to json-schema-migrate-x.
affects: >=1.0.0
gotchaFunctions mutate the input schema object; they do not return a copy.
fix
Clone the schema before passing if original should be preserved: const clone = JSON.parse(JSON.stringify(schema)); migrate.draft7(clone);
affects: >=2.0.0
gotchadraft2019 and draft2020 may introduce $anchor which can conflict with existing $id references.
fix
Review migration output for anchor changes; adjust references accordingly.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: migrate.draft7 is not a function
Using a default import instead of namespace import.
fix
Use 'import * as migrate from "json-schema-migrate-x"' and then call migrate.draft7(schema).
Module '"json-schema-migrate-x"' has no exported member 'draft7'.
Trying to import as named export (e.g., import { draft7 } from 'json-schema-migrate-x').
fix
Use namespace import: import * as migrate from 'json-schema-migrate-x'; then migrate.draft7().
Error: schema is not valid
Passing an invalid JSON Schema that Ajv cannot parse.
fix
Ensure the schema adheres to draft-04 or a known draft; check for syntax errors or unsupported keywords.
Cannot find module 'ajv'
Missing ajv dependency when using the package in a non-standard environment or with bundlers that don't hoist deps.
fix
Install ajv explicitly: npm install ajv
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
ajvrequiredUsed internally to validate and migrate schemas; accessed via migrate.getAjv()
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
json-schema-migrate-x — npm install json-schema-migrate-x · libregistry