# json-schema-migrate

> Migrate JSON-Schema to draft-06

Latest version **2.0.0** (published 2021-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-schema-migrate
pnpm add json-schema-migrate
yarn add json-schema-migrate
bun add json-schema-migrate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-03-28 |
| First published | 2017-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 31.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Evgeny Poberezkin |
| Maintainers | esp |
| Keywords | JSON-Schema, migrate, draft-06 |

## Links

- npm: https://www.npmjs.com/package/json-schema-migrate
- Repository: https://github.com/epoberezkin/json-schema-migrate
- Homepage: https://github.com/epoberezkin/json-schema-migrate#readme
- Issues: https://github.com/epoberezkin/json-schema-migrate/issues
- npm.io page: https://npm.io/package/json-schema-migrate

## Dependencies (1)

- [ajv](https://npm.io/package/ajv.md) ^8.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0 (latest) — 2021-03-28
- 1.0.0-beta.0 (beta) — 2020-12-04
- 1.1.0 — 2021-02-15
- 1.0.0 — 2020-12-13
- 0.2.0 — 2017-04-17
- 0.1.1 — 2017-03-25
- 0.1.0 — 2017-03-25
- 0.0.1 — 2017-03-24

## README

# json-schema-migrate

Migrate JSON-Schema from draft-04 to draft-07, draft-2019-09 or draft-2020-12

[![build](https://github.com/ajv-validator/json-schema-migrate/workflows/build/badge.svg)](https://github.com/ajv-validator/json-schema-migrate/actions?query=workflow%3Abuild)
[![npm](https://img.shields.io/npm/v/json-schema-migrate)](https://www.npmjs.com/package/json-schema-migrate)
[![coverage](https://coveralls.io/repos/github/ajv-validator/json-schema-migrate/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/json-schema-migrate?branch=master)

## Install

```
npm install json-schema-migrate
```

## Usage

```javascript
const migrate = require("json-schema-migrate")
const schema = {
  id: "my-schema",
  minimum: 1,
  exclusiveMinimum: true,
}
migrate.draft7(schema)
// or migrate.draft2019(schema)
// or migrate.draft2020(schema)

console.log(schema)
// {
//  $id: 'my-schema',
//  exclusiveMinimum: 1
// }
```

You can access Ajv instance that is used to migrate schema using `migrate.getAjv` function:

```javascript
console.log(migrate.getAjv().errorsText(errors))
```

## Changes in schemas after migration

- `id` is replaced with `$id`
- `$schema` value becomes draft-07, draft-2019-09 or draft-2020-12 meta-schema
- draft-04 boolean form of `exclusiveMaximum/Minimum` is replaced with the current number form
- `enum` with a single allowed value is replaced with `const`
- Non-standard `constant` is replaced with `const`
- empty schema is replaced with `true`
- schema `{"not":{}}` is replaced with `false`
- `draft2019` function additionally replaces:
  - `definitions` with `$defs`
  - `dependencies` with `dependentRequired` and `dependentSchemas`
  - `"id": "#foo"` with `"$anchor": "foo"`
  - `"id": "schema#foo"` with `"$id": "schema", "$anchor": "foo"`
- `draft2020` function additionally replaces array form of `items` with `prefixItems` (and `additionalItems` with `items`)

## License

[MIT](https://github.com/epoberezkin/json-schema-migrate/blob/master/LICENSE)

---
_Source: https://npm.io/package/json-schema-migrate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
