Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
6a95b7e
Update README.md
epoberezkin Sep 27, 2022
092b88b
Update README.md
epoberezkin Sep 27, 2022
c3f3488
Update README.md
epoberezkin Sep 27, 2022
2e92b23
update typescript, fix broken annotation (#2157)
epoberezkin Nov 13, 2022
7e17b19
Remove unnecessary console.log (#2138)
vargaeric Nov 13, 2022
3e2b806
npm installs version 8 by default (#2088)
VIEWVIEWVIEW Nov 13, 2022
b63bfdf
Doc: update the documentation of addKeyword args (#2090)
TommyDew42 Nov 13, 2022
c3ea653
docs: parsing does not support non-standard JTD keywords (#2072)
avanelli Nov 13, 2022
0c187d9
build(deps-dev): bump husky from 7.0.4 to 8.0.2 (#2153)
dependabot[bot] Nov 13, 2022
b94d7b6
ensure that nullable is not set for required parameters (#2079)
erikbrinkman Nov 13, 2022
1cba474
fix: typo (#2010)
hadrien-toma Nov 13, 2022
a6b069e
docs: fix link for useDefaults (#1955)
bradjones1 Nov 13, 2022
44db016
build(deps-dev): bump @rollup/plugin-commonjs from 21.1.0 to 23.0.2 (…
dependabot[bot] Nov 13, 2022
8ffd933
build(deps-dev): bump fast-uri from 1.0.1 to 2.1.0 (#2007)
dependabot[bot] Nov 13, 2022
f75accb
docs: fix broken links (#2006)
smithc10 Nov 13, 2022
58ec08f
Update security.md -> ReDoS Attack Section (#1953)
efebarlas Nov 13, 2022
e36fa3f
docs: remove invisible character in README (#1990)
is2ei Nov 13, 2022
68ba871
build(deps-dev): bump @rollup/plugin-node-resolve from 13.3.0 to 15.0…
dependabot[bot] Nov 13, 2022
38b8cc0
build(deps-dev): bump mocha from 9.2.2 to 10.0.0 (#1972)
dependabot[bot] Nov 13, 2022
3f83f38
build(deps-dev): bump lint-staged from 12.5.0 to 13.0.3 (#2019)
dependabot[bot] Nov 13, 2022
9ad0a8e
export ValidationError and MissingRefError, closes #1926, closes #184…
dannyb648 Nov 13, 2022
394030f
readme: update group link
epoberezkin Nov 13, 2022
bd8f32b
build(deps-dev): bump @rollup/plugin-json from 4.1.0 to 5.0.1 (#2159)
dependabot[bot] Nov 14, 2022
bd76ffe
remove leading comma in JTD serialisation result, fixes #2001, fixes …
epoberezkin Jan 2, 2023
5cf35ae
JTD empty values schema, fixes #1949 (#2191)
epoberezkin Jan 2, 2023
4dbb427
correctly narrow "number" type to "integer", fixes #1935 (#2192)
epoberezkin Jan 2, 2023
a69a7aa
build(deps-dev): bump @rollup/plugin-typescript from 8.5.0 to 9.0.2 (…
dependabot[bot] Jan 2, 2023
3044d37
special case empty object for jtd (#2158)
erikbrinkman Jan 2, 2023
d88bbb1
build(deps-dev): bump @rollup/plugin-json from 5.0.2 to 6.0.0 (#2183)
dependabot[bot] Jan 2, 2023
3fbe027
build(deps-dev): bump @rollup/plugin-typescript from 9.0.2 to 10.0.1 …
dependabot[bot] Jan 2, 2023
92d02d0
build(deps-dev): bump @rollup/plugin-commonjs from 23.0.7 to 24.0.0 (…
dependabot[bot] Jan 3, 2023
f6999c4
fix JTD discriminator with more than 8 properties, fixes #1971 (#2194)
epoberezkin Jan 3, 2023
7c83077
update node versions (#2195)
epoberezkin Jan 3, 2023
02e6052
docs: update schema language comparison
epoberezkin Jan 8, 2023
08f74e9
update chat badge
epoberezkin May 30, 2023
226bc08
Fix link to `addFormat` docs
laurens Jan 10, 2024
a1848a8
fix: Update parseJson() for v8 11.7.72 and newer
egfx-notifications Dec 20, 2023
b993068
fix: #2330 fixed by removing node 14 (#2379)
jasoniangreen Feb 16, 2024
0d55005
chore: add node 21.x (#2380)
jasoniangreen Feb 18, 2024
bfe9a7a
chore: update dependencies (#2382)
jasoniangreen Feb 23, 2024
83f6db2
fix: minor linting issues (#2383)
jasoniangreen Feb 23, 2024
6023f9c
docs: fix broken link to error logging (#2362)
dsanders11 Mar 9, 2024
522ca5a
Fixing broken links in the docs/packages readme file (#2221)
aristov Mar 9, 2024
45e710a
chore: update prettier to 3.0.3 (#2393)
jasoniangreen Mar 19, 2024
25cfc4f
Add named exports for main classes (#2389) fixes #2381 #2132
benasher44 Mar 29, 2024
07a16d4
chore: update remaining deps except typescript (#2396)
jasoniangreen Mar 30, 2024
55acb2d
chore: bump ajv-formats to 3.0.1 (#2402)
jasoniangreen Mar 30, 2024
30286f5
chore: update typescript to 5.3.3 (#2406)
jasoniangreen Apr 27, 2024
c3be24e
fix: bump node version in publish job (#2423)
jasoniangreen Apr 29, 2024
3e57ce3
readme: build badge (#2424)
epoberezkin Apr 29, 2024
3ee1667
Update workflows (#2410)
rotu May 5, 2024
c8e8688
docs: add warning to maxLength / minLength (#2428)
jasoniangreen May 10, 2024
0822e62
fix: broken link in docs warning (#2431)
jasoniangreen May 11, 2024
fc456fa
compileAsync a schema with discriminator and $ref, fixes #2427 (#2433)
jasoniangreen May 17, 2024
aa74a5e
Replace `uri-js` with `fast-uri` (#2415)
vixalien May 31, 2024
316a415
Revert fast-uri change (#2444)
jasoniangreen Jun 4, 2024
a7ab563
Revert "Revert fast-uri change (#2444)" (#2448)
gurgunday Jun 12, 2024
be4c3b1
fix: ignore new eslint error (#2455)
jasoniangreen Jun 16, 2024
221bdc4
docs: clarify behaviour of addVocabulary (#2454)
jasoniangreen Jun 16, 2024
1557d6a
docs: refactor to improve legibility (#2432)
blottn Jun 19, 2024
5b87d60
Fix grammatical typo in managing-schemas.md (#2305)
wetneb Jun 19, 2024
917f9b5
Update modifying-data.md - fix broken strict-mode link (#2459)
alexanderjsx Jun 30, 2024
e13c3b2
feat: add test for encoded refs and bump fast-uri (#2449)
jasoniangreen Jul 7, 2024
3b94500
fix: changes for @typescript-eslint/array-type rule (#2467)
jasoniangreen Jul 10, 2024
d5821d5
fixes #2217 - clarify custom keyword naming (#2457)
jasoniangreen Jul 10, 2024
ab51992
feat: allow tree-shaking by adding ``"sideEffects": false` to `packag…
josdejong Aug 1, 2024
6c99f9c
fix: #2482 Infinity and NaN serialise to null (#2487)
jasoniangreen Sep 15, 2024
2df8344
fix: small grammatical error in managing-schemas.md (#2508)
monteiro-renato Dec 9, 2024
1830c7f
fix: typos in schema-language.md (#2507)
monteiro-renato Dec 16, 2024
79bbf0f
fix: build errors
vadyvas Oct 28, 2025
e214ccc
ci: update gh workflows to enhance build and publish processes
vadyvas Oct 28, 2025
6820e79
chore: bump version to 8.12.0
vadyvas Oct 28, 2025
5a479f6
chore: bump version to 8.17.1
vadyvas Oct 28, 2025
803fa01
Merge branch 'master' into chore/sync-with-origin
vadyvas Nov 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build
name: build & test

on:
push:
Expand All @@ -12,26 +12,15 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [16.x, 18.x, 20.x, 21.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: git submodule update --init
# - name: update website
# if: ${{ github.event_name == 'push' && matrix.node-version == '14.x' }}
# run: ./scripts/publish-site
# env:
# GH_TOKEN_PUBLIC: ${{ secrets.GH_TOKEN_PUBLIC }}
# GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
# GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
- run: npm run build
- run: npm run test-ci
# - name: coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 8 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ on:
jobs:
publish-npm:
runs-on: ubuntu-latest
permissions:
id-token: write # Required for OIDC
contents: read
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
registry-url: https://registry.npmjs.org/
node-version: 18
- run: npm install
- run: git submodule update --init
- run: npm run test-ci
- name: Publish beta version to npm
if: "github.event.release.prerelease"
if: ${{ github.event.release.prerelease }}
run: npm publish --tag beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm
if: "!github.event.release.prerelease"
if: ${{ !github.event.release.prerelease }}
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ The fastest JSON validator for Node.js and browser.

Supports JSON Schema draft-04/06/07/2019-09/2020-12 ([draft-04 support](https://ajv.js.org/json-schema.html#draft-04) requires ajv-draft-04 package) and JSON Type Definition [RFC8927](https://datatracker.ietf.org/doc/rfc8927/).

[![build](https://github.com/ajv-validator/ajv/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
[![build](https://github.com/ajv-validator/ajv/actions/workflows/build.yml/badge.svg)](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
[![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv)
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv)
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master)
[![SimpleX](https://img.shields.io/badge/chat-on%20SimpleX-%2307b4b9)](https://simplex.chat/contact#/?v=1&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2Fap4lMFzfXF8Hzmh-Vz0WNxp_1jKiOa-h%23MCowBQYDK2VuAyEAcdefddRvDfI8iAuBpztm_J3qFucj8MDZoVs_2EcMTzU%3D)
[![SimpleX](https://img.shields.io/badge/chat-on%20SimpleX-70F0F9)](https://simplex.chat/contact#/?v=1-2&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2F8KvvURM6J38Gdq9dCuPswMOkMny0xCOJ%23%2F%3Fv%3D1-2%26dh%3DMCowBQYDK2VuAyEAr8rPVRuMOXv6kwF2yUAap-eoVg-9ssOFCi1fIrxTUw0%253D%26srv%3Do5vmywmrnaxalvz6wi3zicyftgio6psuvyniis6gco6bp6ekl4cqj4id.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%224pwLRgWHU9tlroMWHz0uOg%3D%3D%22%7D)
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)
[![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin)

Expand All @@ -35,6 +35,7 @@ Please review [Contributing guidelines](./CONTRIBUTING.md) and [Code components]
All documentation is available on the [Ajv website](https://ajv.js.org).

Some useful site links:

- [Getting started](https://ajv.js.org/guide/getting-started.html)
- [JSON Schema vs JSON Type Definition](https://ajv.js.org/guide/schema-language.html)
- [API reference](https://ajv.js.org/api.html)
Expand All @@ -53,7 +54,7 @@ Your continuing support is very important - the funds will be used to develop an
Please sponsor Ajv via:

- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it)
- [Ajv Open Collective️](https://opencollective.com/ajv)
- [Ajv Open Collective](https://opencollective.com/ajv)

Thank you.

Expand All @@ -73,6 +74,19 @@ Thank you.
<a href="https://opencollective.com/ajv/organization/9/website"><img src="https://opencollective.com/ajv/organization/9/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/10/website"><img src="https://opencollective.com/ajv/organization/10/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/11/website"><img src="https://opencollective.com/ajv/organization/11/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/12/website"><img src="https://opencollective.com/ajv/organization/12/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/13/website"><img src="https://opencollective.com/ajv/organization/13/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/14/website"><img src="https://opencollective.com/ajv/organization/14/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/15/website"><img src="https://opencollective.com/ajv/organization/15/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/16/website"><img src="https://opencollective.com/ajv/organization/16/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/17/website"><img src="https://opencollective.com/ajv/organization/17/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/18/website"><img src="https://opencollective.com/ajv/organization/18/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/19/website"><img src="https://opencollective.com/ajv/organization/19/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/20/website"><img src="https://opencollective.com/ajv/organization/20/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/21/website"><img src="https://opencollective.com/ajv/organization/21/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/22/website"><img src="https://opencollective.com/ajv/organization/22/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/23/website"><img src="https://opencollective.com/ajv/organization/23/avatar.svg"></a>
<a href="https://opencollective.com/ajv/organization/24/website"><img src="https://opencollective.com/ajv/organization/24/avatar.svg"></a>

## Performance

Expand All @@ -87,7 +101,7 @@ Currently Ajv is the fastest and the most standard compliant validator according

Performance of different validators by [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark):

[![performance](https://chart.googleapis.com/chart?chxt=x,y&cht=bhs&chco=76A4FB&chls=2.0&chbh=62,4,1&chs=600x416&chxl=-1:|ajv|@exodus&#x2F;schemasafe|is-my-json-valid|djv|@cfworker&#x2F;json-schema|jsonschema&chd=t:100,69.2,51.5,13.1,5.1,1.2)](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
[![performance](https://chart.googleapis.com/chart?chxt=x,y&cht=bhs&chco=76A4FB&chls=2.0&chbh=62,4,1&chs=600x416&chxl=-1:|ajv|@exodus/schemasafe|is-my-json-valid|djv|@cfworker/json-schema|jsonschema/=t:100,69.2,51.5,13.1,5.1,1.2)](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)

## Features

Expand Down Expand Up @@ -144,15 +158,15 @@ const schema = {
type: "object",
properties: {
foo: {type: "integer"},
bar: {type: "string"}
bar: {type: "string"},
},
required: ["foo"],
additionalProperties: false,
}

const data = {
foo: 1,
bar: "abc"
bar: "abc",
}

const validate = ajv.compile(schema)
Expand Down
8 changes: 5 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Every time this method is called the errors are overwritten so you need to copy

If the schema is asynchronous (has `$async` keyword on the top level) this method returns a Promise. See [Asynchronous validation](./guide/async-validation.md).

<a name="add-schema"></a>
<a id="add-schema"></a>

### ajv.addSchema(schema: object | object[], key?: string): Ajv

Expand Down Expand Up @@ -245,13 +245,13 @@ Formats can be also added via `formats` option.

<a name="api-addkeyword"></a>

### ajv.addKeyword(definition: object): Ajv
### ajv.addKeyword(definition: string | object): Ajv

Add validation keyword to Ajv instance.

Keyword should be different from all standard JSON Schema keywords and different from previously defined keywords. There is no way to redefine keywords or to remove keyword definition from the instance.

Keyword must start with a letter, `_` or `$`, and may continue with letters, numbers, `_`, `$`, or `-`.
Keyword must start with an ASCII letter, `_` or `$`, and may continue with ASCII letters, numbers, `_`, `$`, `-`, or `:`.
It is recommended to use an application-specific prefix for keywords to avoid current and future name collisions.

Example Keywords:
Expand Down Expand Up @@ -297,6 +297,8 @@ interface KeywordDefinition {
}
```

If only the property `keyword` is provided in the definition object, you can also pass the keyword name as the argument.

`compile`, `macro` and `code` are mutually exclusive, only one should be used at a time. `validate` can be used separately or in addition to `compile` or `macro` to support [\$data reference](./guide/combining-schemas.md#data-reference).

::: tip Keyword is validated only for applicable data types
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/combining-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ajv = new Ajv()
const validate = ajv.addSchema(defsSchema).compile(schema)
```

See [Options](./api.md#options) and [addSchema](./api.md#add-schema) method.
See [Options](../options.md) and [addSchema](../api.md#add-schema) method.

::: tip Reference resolution
- `$ref` is resolved as the uri-reference using schema \$id as the base URI (see the example).
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
You can try Ajv without installing it in the Node.js REPL: [https://runkit.com/npm/ajv](https://runkit.com/npm/ajv)
:::

To install Ajv version 7:
To install Ajv version 8:

```bash
npm install ajv
Expand Down Expand Up @@ -140,8 +140,8 @@ const parse = ajv.compileParser(schema)
const json = '{"foo": 1, "bar": "abc"}'
const invalidJson = '{"unknown": "abc"}'

console.log(parseAndLog(json)) // logs {foo: 1, bar: "abc"}
console.log(parseAndLog(invalidJson)) // logs error and position
parseAndLog(json) // logs {foo: 1, bar: "abc"}
parseAndLog(invalidJson) // logs error and position

function parseAndLog(json) {
const data = parse(json)
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/managing-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ app.post("/user", async (cxt) => {
</code-group>

::: warning Use single Ajv instance
It recommended to use a single Ajv instance for the whole application, so if you use validation in more than one module, you should:
It is recommended to use a single Ajv instance for the whole application, so if you use validation in more than one module, you should:

- require Ajv in a separate module responsible for validation
- compile all validators there
Expand Down Expand Up @@ -186,7 +186,7 @@ In the example above, the key passed to the `addSchema` method was used to retri

### Pre-adding all schemas vs adding on demand

In the example above all schemas were added in advance. It is also possible, to add schemas as they are used - it can be helpful if there is many schemas. In this case, you need to check first whether the schema is already added by calling `getSchema` method - it would return `undefined` if not:
In the example above all schemas were added in advance. It is also possible, to add schemas as they are used - it can be helpful if there are many schemas. In this case, you need to check first whether the schema is already added by calling `getSchema` method - it would return `undefined` if not:

```javascript
const schema_user = require("./schema_user.json")
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/modifying-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ See [discriminator](../json-schema.md#discriminator) keyword.

## Assigning defaults

With [option `useDefaults`](./api.md#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.
With [option `useDefaults`](./options.md#options) Ajv will assign values from `default` keyword in the schemas of `properties` and `items` (when it is the array of schemas) to the missing properties and items.

With the option value `"empty"` properties and items equal to `null` or `""` (empty string) will be considered missing and assigned defaults.

Expand Down Expand Up @@ -210,7 +210,7 @@ With `useDefaults` option `default` keywords throws exception during schema comp

The strict mode option can change the behaviour for these unsupported defaults (`strict: false` to ignore them, `"log"` to log a warning).

See [Strict mode](./strict-mode.md).
See [Strict mode](../strict-mode.md).

::: tip Default with discriminator keyword
Defaults will be assigned in schemas inside `oneOf` in case [discriminator](../json-schema.md#discriminator) keyword is used.
Expand Down
19 changes: 11 additions & 8 deletions docs/guide/schema-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
tags:
- JTD
---

# Choosing schema language

[[toc]]
Expand Down Expand Up @@ -70,7 +71,7 @@ Draft-2019-09 support is provided via a separate export in order to avoid increa
With this import Ajv supports the following features:

- keywords [`unevaluatedProperties`](../json-schema.md#unevaluatedproperties) and [`unevaluatedItems`](../json-schema.md#unevaluateditems)
- keywords [`dependentRequired`](../json-schema.md#dependentrequired), [`dependentSchemas`](../json-schema.md#dependentschemas), [`maxContains`/`minContain`](../json-schema.md#maxcontains--mincontains)
- keywords [`dependentRequired`](../json-schema.md#dependentrequired), [`dependentSchemas`](../json-schema.md#dependentschemas), [`maxContains`/`minContains`](../json-schema.md#maxcontains-mincontains)
- dynamic recursive references with [`recursiveAnchor`/`recursiveReference`] - see [Extending recursive schemas](./combining-schemas.md#extending-recursive-schemas)
- draft-2019-09 meta-schema is the default.

Expand Down Expand Up @@ -123,17 +124,19 @@ See [JSON Schema](../json-schema.md) for more information and the list of define
- Defines the shape of JSON data via strictly defined schema forms (rather than the collection of restrictions).
- Effective support for tagged unions.
- Designed to protect against user mistakes.
- Supports compilation of schemas to efficient [serializers and parsers](./getting-started.md#parsing-and-serializing-json) (no need to validate as a separate step)
- Approved as [RFC8927](https://datatracker.ietf.org/doc/rfc8927/)
- Supports compilation of schemas to efficient [serializers and parsers](./getting-started.md#parsing-and-serializing-json) (no need to validate as a separate step).
- Approved as [RFC8927](https://datatracker.ietf.org/doc/rfc8927/).
- Substantial industry adoption since it was standardized in 2020, Ajv v8.12.0 fixed all reported JTD bugs.

**Cons**:

- Limited, compared with JSON Schema - no support for untagged unions<sup>\*</sup>, conditionals, references between different schema files<sup>\*\*</sup>, etc.
- No meta-schema in the specification<sup>\*</sup>.
- Brand new - limited industry adoption (as of January 2021).
- Limited, compared with JSON Schema - no support for untagged unions<sup>1</sup>, conditionals, references between different schema files<sup>2</sup>, etc.
- No meta-schema in the specification<sup>3</sup>.

<sup>1</sup> Ajv defines non-standard keyword "union" that can be used inside "metadata" object.

<sup>\*</sup> Ajv defines meta-schema for JTD schemas and non-standard keyword "union" that can be used inside "metadata" object.
<sup>2</sup> You can still combine schemas from multiple files in the application code.

<sup>\*\*</sup> You can still combine schemas from multiple files in the application code.
<sup>3</sup> Ajv defines meta-schema for JTD schemas.

See [JSON Type Definition](../json-type-definition.md) for more information and the list of defined schema forms.
10 changes: 7 additions & 3 deletions docs/json-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ The value of the keyword should be a number. The data to be valid should be a mu

### `maxLength` / `minLength`

::: warning Grapheme clusters will count as multiple characters
Certain charsets have characters that are made up of multiple Unicode code points. These [grapheme clusters](https://www.unicode.org/reports/tr29/tr29-17.html#Grapheme_Cluster_Boundaries) are counted as multiple in length calculations.
:::

The value of the keywords should be a number. The data to be valid should have length satisfying this rule. Unicode pairs are counted as a single character.

**Examples**
Expand Down Expand Up @@ -474,11 +478,11 @@ To create and equivalent schema in draft-2020-12 use keywords [prefixItems](#pre

The value of the keyword should be a boolean or an object.

If `items` keyword is not present or it is an object, `additionalItems` keyword should be ignored regardless of its value. By default Ajv will throw exception in this case - see [Strict mode](./strict-mode.md)
`additionalItems` keyword is ignored if `items` keyword is not present or is an object. By default Ajv will throw exception in this case - see [Strict mode](./strict-mode.md)

If `items` keyword is an array and data array has not more items than the length of `items` keyword value, `additionalItems` keyword is also ignored.
`additionalItems` keyword is ignored if `items` keyword has more elements than data array.

If the length of data array is bigger than the length of "items" keyword value than the result of the validation depends on the value of `additionalItems` keyword:
If the data array has more elements than the `items` keyword value then the result of the validation depends on the value of `additionalItems` keyword:

- `false`: data is invalid
- `true`: data is valid
Expand Down
4 changes: 4 additions & 0 deletions docs/json-type-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ Any user-defined keywords that can be used in JSON Schema schemas can also be us
It is strongly recommended to only use it to simplify migration from JSON Schema to JTD and not to use non-standard keywords in the new schemas, as these keywords are not supported by any other tools.
:::

::: warning Parsing does NOT support non-standard JTD keywords
compileParser method does not support non-standard JTD keywords, you will have to use JSON.parse and then validates.
:::

## Validation errors

TODO
2 changes: 1 addition & 1 deletion docs/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ ajv.addKeyword({
})
```

Macro keywords an be recursive - i.e. return schemas containing the same keyword. See the example of defining a recursive macro keyword `deepProperties` in the [test](https://github.com/ajv-validator/ajv/blob/master/spec/keyword.spec.ts#L316).
Macro keywords can be recursive - i.e. return schemas containing the same keyword. See the example of defining a recursive macro keyword `deepProperties` in the [test](https://github.com/ajv-validator/ajv/blob/master/spec/keyword.spec.ts#L316).

## Schema compilation context

Expand Down
Loading