{"id":48281,"library":"json-schema-migrate","title":"json-schema-migrate","description":"Migrates JSON Schema between drafts: draft-04 to draft-07, draft-2019-09, or draft-2020-12. Current stable version is 2.0.0. Maintained as part of the Ajv validator ecosystem. Key differentiators: supports multiple target drafts, handles draft-04-specific patterns like boolean exclusiveMinimum, single-value enum to const, and empty/not schemas. Release cadence is low; updates are infrequent. Alternatives include manual schema transformation or using Ajv's own migration utilities, but this package provides a dedicated, focused tool.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/epoberezkin/json-schema-migrate","tags":["javascript","JSON-Schema","migrate","draft-06"],"install":[{"cmd":"npm install json-schema-migrate","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-migrate","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-migrate","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Ajv is used internally to validate and migrate schemas; the package uses a bundled Ajv instance.","package":"ajv","optional":false}],"imports":[{"note":"The package does not provide an ESM entry; use require() in Node. For ES modules, use createRequire or dynamic import.","wrong":"import migrate from 'json-schema-migrate' (CJS-only package, no ESM)","symbol":"default","correct":"const migrate = require('json-schema-migrate')"},{"note":"Function names are draft7, draft2019, draft2020 – no leading zeros in draft-07 name.","wrong":"migrate.draft07(schema) (incorrect function name)","symbol":"draft7","correct":"migrate.draft7(schema)"},{"note":"Functions mutate the schema object in place and return nothing.","wrong":"migrate.draft2019(schema, options) (no second argument)","symbol":"draft2019","correct":"migrate.draft2019(schema)"}],"quickstart":{"code":"const migrate = require('json-schema-migrate');\nconst oldSchema = {\n  id: 'my-schema',\n  type: 'string',\n  minimum: 1,\n  exclusiveMinimum: true\n};\nmigrate.draft7(oldSchema);\nconsole.log(JSON.stringify(oldSchema, null, 2));\n// Output:\n// {\n//   \"$id\": \"my-schema\",\n//   \"type\": \"string\",\n//   \"exclusiveMinimum\": 1\n// }","lang":"javascript","description":"Shows migrating a draft-04 schema with boolean exclusiveMinimum to draft-07, using default import and draft7 function."},"warnings":[{"fix":"Clone the schema first: const cloned = JSON.parse(JSON.stringify(original));","message":"The migration mutates the input schema object in place. Do not pass an object you need to keep unchanged.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use 'const' directly in your source schema.","message":"The 'constant' keyword (non-standard) is replaced with 'const' during migration. If you rely on 'constant', update your schema.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"After migration, use '$defs' instead of 'definitions'.","message":"draft2019 migration rewrites 'definitions' to '$defs'. Any code referencing 'schema.definitions' will break after migration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update Node to >=6.0.0 and replace 'migrate.ajv' with 'migrate.getAjv()'.","message":"Version 2.0.0 dropped support for Node < 6.0.0. Also, the package no longer exports a bundled Ajv instance via 'migrate.ajv'; use 'migrate.getAjv()' instead.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"After migration, update any logic that accesses schema.items to handle the new prefixItems structure.","message":"The 'draft2020' migration converts array 'items' to 'prefixItems' and renames 'additionalItems' to 'items'. This can break existing consumers expecting the old structure.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'-04':11,43 '-06':91 '-07':14 '-09':17 '-12':21 '-2019':16 '-2020':20 '2.0.0':26 'ajv':32,72 'altern':65 'boolean':47 'cadenc':59 'const':54 'current':22 'dedic':82 'differenti':36 'draft':9,10,13,15,19,40,42,90 'ecosystem':34 'empty/not':56 'enum':52 'exclusiveminimum':48 'focus':83 'handl':41 'includ':66 'infrequ':64 'javascript':85 'json':2,6,87 'json-schema':86 'json-schema-migr':1 'key':35 'like':46 'low':61 'maintain':27 'manual':67 'migrat':4,5,75,89 'multipl':38 'packag':79 'part':29 'pattern':45 'provid':80 'releas':58 'schema':3,7,57,68,88 'singl':50 'single-valu':49 'specif':44 'stabl':23 'support':37 'target':39 'tool':84 'transform':69 'updat':62 'use':71 'util':76 'valid':33 'valu':51 'version':24","created_at":"2026-06-07T16:55:49.816357+00:00","updated_at":"2026-06-07T16:55:49.816357+00:00","problems":[{"fix":"Ensure the schema object is mutable (not frozen or from a read-only source like Object.freeze).","cause":"Trying to migrate a frozen or read-only schema object; migration mutates the schema.","error":"TypeError: Cannot assign to read only property 'type' of object '#'"},{"fix":"Use const migrate = require('json-schema-migrate'); (CJS) or dynamic import with .default property: const migrate = (await import('json-schema-migrate')).default;","cause":"Incorrect default import; package is CJS-only, so using ESM import may result in an object without the expected functions.","error":"migrate.draft7 is not a function"},{"fix":"Ensure the schema is a valid JSON Schema draft-04 object; check for missing required properties or malformed keywords.","cause":"The input schema is syntactically invalid according to draft-04. Migration runs validation before transforming.","error":"Schema is not valid JSON Schema"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/epoberezkin/json-schema-migrate#readme","github":"https://github.com/epoberezkin/json-schema-migrate","docs":null,"changelog":null,"pypi":null,"npm":"json-schema-migrate","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}