Registry / devops / alterschema

alterschema

JSON →
library1.1.3jsnpmunverified

A language-independent tool to automatically transform JSON Schema documents across specification versions (Draft 3 to 2020-12). Version 1.1.3 is the latest stable release. Developed by Sourcemeta, it provides lossless, transitive transformations and a JavaScript binding. Differentiates from other converters by offering formal one-to-one rule mappings and a web playground at alterschema.sourcemeta.com. Supports lossless upgrades from 2019-09 to 2020-12, Draft 7 to 2019-09, etc. Designed for compatibility with JSON Schema validators.

npm install alterschema
INSTALL
IMPORT
SIG · ALTERSCHEMA
A
alterschema
devopsjavascriptv1.1.3
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.

alterschema
const alterschema = require('alterschema')
The package exports a single async function; there is no default import. Use require() for CommonJS.
alterschema as ES module
import alterschema from 'alterschema'
import { alterschema } from 'alterschema'
The package has a default export. Named import will fail.
TypeScript types
// No official types; use @types/alterschema or define own
Package does not ship TypeScript declarations. Use a custom .d.ts file.

Converts a JSON Schema from 2019-09 to 2020-12 using the alterschema function.

const alterschema = require('alterschema'); async function main() { const schema = { $schema: 'https://json-schema.org/draft/2019-09/schema', type: 'object', properties: { name: { type: 'string' } } }; try { const result = await alterschema(schema, '2019-09', '2020-12'); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Transformation failed:', error); } } main();
Debug
Known issues
gotchaThe function is async: must be awaited or chained with .then().
fix
Use await alterschema(...) or .then()
affects: >=0.0.0
gotchaInput schema must include the $schema keyword; otherwise from version is ignored.
fix
Add "$schema": "<from-version-url>" to your schema.
affects: >=1.0.0
gotchaTransformations are transitive but Minimal coverage for draft3 to draft4.
fix
Check issues for draft3 support; consider manual migration.
affects: >=1.0.0
gotchaPackage does not provide TypeScript types.
fix
Create your own .d.ts or use `// @ts-ignore`
affects: >=1.0.0
gotchaThe command-line tool and JavaScript API are the only official bindings.
fix
Use the npm package or CLI for Node.js.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: alterschema is not a function
Using default import from ESM with named import syntax: `import { alterschema } from 'alterschema'`
fix
Use `import alterschema from 'alterschema'` or `const alterschema = require('alterschema')`
Error: Schema does not have an $schema keyword
Input schema missing the $schema property
fix
Add `$schema: 'https://json-schema.org/...` to your schema object
Error: Unknown from version 'draft-04'
Using incorrect version string (e.g., 'draft-04' instead of 'draft4')
fix
Use the exact version identifier: 'draft3', 'draft4', 'draft6', 'draft7', '2019-09', '2020-12'
TypeError: Cannot read properties of undefined (reading 'apply')
The alterschema function was called without awaiting the async function
fix
Ensure you use `await alterschema(...)` or chain `.then()`
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
json-eoptionalRequired for evaluating transformation rules written in JSON-e
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
alterschema — npm install alterschema · libregistry