ajv
Another JSON Schema Validator
Last updated 4 years ago by esp .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install ajv 
SYNC missed versions from official npm registry.
Ajv logo

 

Ajv: Another JSON schema validator

Super fast JSON validator for Node.js and browser.

Supports JSON Schema draft-06/07/2019-09/2020-12 (draft-04 is supported in version 6) and JSON Type Definition RFC8927.

build npm npm (beta) npm downloads Coverage Status Gitter GitHub Sponsors

Platinum sponsors

Using version 7

Ajv version 7 has these new features:

  • NEW: support of JSON Type Definition RFC8927 (from v7.1.0), including generation of serializers and parsers from JTD schemas that are more efficient than native JSON serialization/parsing, combining JSON string parsing and validation in one function.
  • support of JSON Schema draft-2019-09 features: unevaluatedProperties and unevaluatedItems, dynamic recursive references and other additional keywords.
  • to reduce the mistakes in JSON schemas and unexpected validation results, strict mode is added - it prohibits ignored or ambiguous JSON Schema elements.
  • to make code injection from untrusted schemas impossible, code generation is fully re-written to be safe and to allow code optimization (compiled schema code size is reduced by more than 10%).
  • to simplify Ajv extensions, the new keyword API that is used by pre-defined keywords is available to user-defined keywords - it is much easier to define any keywords now, especially with subschemas. ajv-keywords package was updated to use the new API (in v4.0.0)
  • schemas are compiled to ES6 code (ES5 code generation is also supported with an option).
  • to improve reliability and maintainability the code is migrated to TypeScript.

Please note:

  • the support for JSON-Schema draft-04 is removed - if you have schemas using "id" attributes you have to replace them with "$id" (or continue using Ajv v6 that will be supported until 02/28/2021).
  • all formats are separated to ajv-formats package - they have to be explicitly added if you use them.

See release notes for the details.

To install the new version:

npm install ajv

See Getting started for code example.

Contributing

More than 100 people contributed to Ajv, and we would love to have you join the development. We welcome implementing new features that will benefit many users and ideas to improve our documentation.

At Ajv, we are committed to creating more equitable and inclusive spaces for our community and team members to contribute to discussions that affect both this project and our ongoing work in the open source ecosystem.

We strive to create an environment of respect and healthy discourse by setting standards for our interactions and we expect it from all members of our community - from long term project member to first time visitor. For more information, review our code of conduct and values.

<Contributors />

How we make decisions

We value conscious curation of our library size, and balancing performance and functionality. To that end, we cannot accept every suggestion. When evaluating pull requests we consider:

  • Will this benefit many users or a niche use case?
  • How will this impact the performance of Ajv?
  • How will this expand our library size?

To help us evaluate and understand, when you submit an issue and pull request:

  • Explain why this feature is important to the user base
  • Include documentation
  • Include test coverage with any new feature implementations

Please include documentation and test coverage with any new feature implementations.

To run tests:

npm install
git submodule update --init
npm test

npm run build - compiles typescript to dist folder.

Please also review Contributing guidelines and Code components.

Contents

Mozilla MOSS grant and OpenJS Foundation

Ajv has been awarded a grant from Mozilla’s Open Source Support (MOSS) program in the “Foundational Technology” track! It will sponsor the development of Ajv support of JSON Schema version 2019-09 and of JSON Type Definition (RFC8927).

Ajv also joined OpenJS Foundation – having this support will help ensure the longevity and stability of Ajv for all its users.

This blog post has more details.

I am looking for the long term maintainers of Ajv – working with ReadySet, also sponsored by Mozilla, to establish clear guidelines for the role of a "maintainer" and the contribution standards, and to encourage a wider, more inclusive, contribution from the community.

Please sponsor Ajv development

Since I asked to support Ajv development 40 people and 6 organizations contributed via GitHub and OpenCollective - this support helped receiving the MOSS grant!

Your continuing support is very important - the funds will be used to develop and maintain Ajv once the next major version is released.

Please sponsor Ajv via:

Thank you.

Open Collective sponsors

Performance

Ajv generates code to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.

Currently Ajv is the fastest and the most standard compliant validator according to these benchmarks:

Performance of different validators by json-schema-benchmark:

performance

Features

Install

To install version 7:

npm install ajv

Getting started

Try it in the Node.js REPL: https://runkit.com/npm/ajv

In JavaScript:

// or ESM/TypeScript import
import Ajv from "ajv"
// Node.js require:
const Ajv = require("ajv")

const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) console.log(validate.errors)

See more examples in Guide: getting started

Extending Ajv

User defined keywords

See section in data validation and the detailed guide.

Plugins

Ajv can be extended with plugins that add keywords, formats or functions to process generated code. When such plugin is published as npm package it is recommended that it follows these conventions:

  • it exports a function that accepts ajv instance as the first parameter - it allows using plugins with ajv-cli.
  • this function returns the same instance to allow chaining.
  • this function can accept an optional configuration as the second parameter.

You can import Plugin interface from ajv if you use Typescript.

If you have published a useful plugin please submit a PR to add it to the next section.

Related packages

  • ajv-bsontype - plugin to validate mongodb's bsonType formats
  • ajv-cli - command line interface
  • ajv-formats - formats defined in JSON Schema specification
  • ajv-errors - plugin for defining error messages in the schema
  • ajv-i18n - internationalised error messages
  • ajv-istanbul - plugin to instrument generated validation code to measure test coverage of your schemas
  • ajv-keywords - plugin with additional validation keywords (select, typeof, etc.)
  • ajv-merge-patch - plugin with keywords $merge and $patch
  • ajv-formats-draft2019 - format validators for draft2019 that aren't included in ajv-formats (ie. idn-hostname, idn-email, iri, iri-reference and duration)

Some packages using Ajv

Changes history

See https://github.com/ajv-validator/ajv/releases

Please note: Changes in version 7.0.0

Version 6.0.0.

Code of conduct

Please review and follow the Code of conduct.

Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team.

Security contact

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerabilities via GitHub issues.

Open-source software support

Ajv is a part of Tidelift subscription - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers.

License

MIT

Current Tags

  • 4.11.8                                ...           4.x (8 years ago)
  • 8.11.1                                ...           beta (2 years ago)
  • 8.17.1                                ...           latest (4 months ago)

355 Versions

  • 8.17.1                                ...           4 months ago
  • 8.16.0                                ...           5 months ago
  • 8.15.0                                ...           5 months ago
  • 8.14.0                                ...           6 months ago
  • 8.13.0                                ...           7 months ago
  • 8.12.0                                ...           2 years ago
  • 8.11.2                                ...           2 years ago
  • 8.11.1                                ...           2 years ago
  • 8.11.0                                ...           3 years ago
  • 8.10.0                                ...           3 years ago
  • 8.9.0                                ...           3 years ago
  • 8.8.2                                ...           3 years ago
  • 8.8.1                                ...           3 years ago
  • 8.8.0                                ...           3 years ago
  • 8.7.1                                ...           3 years ago
  • 8.7.0                                ...           3 years ago
  • 8.6.3                                ...           3 years ago
  • 8.6.2                                ...           3 years ago
  • 8.6.1                                ...           3 years ago
  • 8.6.0                                ...           3 years ago
  • 8.5.0                                ...           3 years ago
  • 8.4.0                                ...           4 years ago
  • 8.3.0                                ...           4 years ago
  • 8.2.0                                ...           4 years ago
  • 8.1.0                                ...           4 years ago
  • 8.0.5                                ...           4 years ago
  • 8.0.4                                ...           4 years ago
  • 8.0.3                                ...           4 years ago
  • 8.0.2                                ...           4 years ago
  • 8.0.1                                ...           4 years ago
  • 8.0.0                                ...           4 years ago
  • 7.2.4                                ...           4 years ago
  • 8.0.0-beta.4                                ...           4 years ago
  • 8.0.0-beta.3                                ...           4 years ago
  • 7.2.3                                ...           4 years ago
  • 7.2.2                                ...           4 years ago
  • 8.0.0-beta.2                                ...           4 years ago
  • 8.0.0-beta.1                                ...           4 years ago
  • 8.0.0-beta.0                                ...           4 years ago
  • 7.2.1                                ...           4 years ago
  • 7.2.0                                ...           4 years ago
  • 7.1.1                                ...           4 years ago
  • 7.1.0                                ...           4 years ago
  • 7.0.4                                ...           4 years ago
  • 7.0.3                                ...           4 years ago
  • 7.0.2                                ...           4 years ago
  • 7.0.1                                ...           4 years ago
  • 7.0.0                                ...           4 years ago
  • 7.0.0-rc.5                                ...           4 years ago
  • 7.0.0-rc.4                                ...           4 years ago
  • 7.0.0-rc.3                                ...           4 years ago
  • 7.0.0-rc.2                                ...           4 years ago
  • 7.0.0-rc.1                                ...           4 years ago
  • 7.0.0-rc.0                                ...           4 years ago
  • 7.0.0-beta.9                                ...           4 years ago
  • 7.0.0-beta.8                                ...           4 years ago
  • 7.0.0-beta.7                                ...           4 years ago
  • 7.0.0-beta.6                                ...           4 years ago
  • 7.0.0-beta.5                                ...           4 years ago
  • 7.0.0-beta.4                                ...           4 years ago
  • 7.0.0-beta.3                                ...           4 years ago
  • 7.0.0-beta.2                                ...           4 years ago
  • 7.0.0-beta.1                                ...           4 years ago
  • 6.12.6                                ...           4 years ago
  • 7.0.0-beta.0                                ...           4 years ago
  • 7.0.0-alpha.1                                ...           4 years ago
  • 7.0.0-alpha.0                                ...           4 years ago
  • 6.12.5                                ...           4 years ago
  • 6.12.4                                ...           4 years ago
  • 6.12.3                                ...           4 years ago
  • 6.12.2                                ...           5 years ago
  • 6.12.1                                ...           5 years ago
  • 6.12.0                                ...           5 years ago
  • 6.11.0                                ...           5 years ago
  • 6.10.2                                ...           5 years ago
  • 6.10.1                                ...           5 years ago
  • 6.10.0                                ...           6 years ago
  • 6.9.2                                ...           6 years ago
  • 6.9.1                                ...           6 years ago
  • 6.9.0                                ...           6 years ago
  • 6.8.1                                ...           6 years ago
  • 6.8.0                                ...           6 years ago
  • 6.7.0                                ...           6 years ago
  • 6.6.2                                ...           6 years ago
  • 6.6.1                                ...           6 years ago
  • 6.6.0                                ...           6 years ago
  • 6.5.5                                ...           6 years ago
  • 6.5.4                                ...           6 years ago
  • 6.5.3                                ...           6 years ago
  • 6.5.2                                ...           6 years ago
  • 6.5.1                                ...           6 years ago
  • 6.5.0                                ...           7 years ago
  • 6.4.0                                ...           7 years ago
  • 6.3.0                                ...           7 years ago
  • 6.2.1                                ...           7 years ago
  • 6.2.0                                ...           7 years ago
  • 6.1.1                                ...           7 years ago
  • 6.1.0                                ...           7 years ago
  • 6.0.1                                ...           7 years ago
  • 6.0.0                                ...           7 years ago
  • 5.5.2                                ...           7 years ago
  • 6.0.0-rc.1                                ...           7 years ago
  • 5.5.1                                ...           7 years ago
  • 6.0.0-rc.0                                ...           7 years ago
  • 5.5.0                                ...           7 years ago
  • 5.4.0                                ...           7 years ago
  • 6.0.0-beta.2                                ...           7 years ago
  • 6.0.0-beta.1                                ...           7 years ago
  • 6.0.0-beta.0                                ...           7 years ago
  • 5.3.0                                ...           7 years ago
  • 5.2.5                                ...           7 years ago
  • 5.2.4                                ...           7 years ago
  • 5.2.3                                ...           7 years ago
  • 5.2.2                                ...           7 years ago
  • 5.2.1                                ...           7 years ago
  • 5.2.0                                ...           7 years ago
  • 5.1.6                                ...           7 years ago
  • 5.1.5                                ...           7 years ago
  • 5.1.4                                ...           7 years ago
  • 5.1.3                                ...           7 years ago
  • 5.1.2                                ...           7 years ago
  • 5.1.1                                ...           8 years ago
  • 5.1.0                                ...           8 years ago
  • 5.0.1                                ...           8 years ago
  • 4.11.8                                ...           8 years ago
  • 5.0.0                                ...           8 years ago
  • 4.11.7                                ...           8 years ago
  • 5.0.4-beta.3                                ...           8 years ago
  • 4.11.6                                ...           8 years ago
  • 5.0.4-beta.2                                ...           8 years ago
  • 5.0.4-beta.1                                ...           8 years ago
  • 5.0.4-beta.0                                ...           8 years ago
  • 4.11.5                                ...           8 years ago
  • 4.11.4                                ...           8 years ago
  • 5.0.3-beta.0                                ...           8 years ago
  • 5.0.2-beta.0                                ...           8 years ago
  • 4.11.3                                ...           8 years ago
  • 5.0.1-beta.3                                ...           8 years ago
  • 5.0.1-beta.2                                ...           8 years ago
  • 4.11.2                                ...           8 years ago
  • 4.11.1                                ...           8 years ago
  • 4.11.0                                ...           8 years ago
  • 5.0.1-beta.1                                ...           8 years ago
  • 4.10.4                                ...           8 years ago
  • 5.0.1-beta.0                                ...           8 years ago
  • 4.10.3                                ...           8 years ago
  • 4.10.2                                ...           8 years ago
  • 4.10.1                                ...           8 years ago
  • 4.10.0                                ...           8 years ago
  • 4.9.3                                ...           8 years ago
  • 4.9.2                                ...           8 years ago
  • 4.9.1                                ...           8 years ago
  • 5.0.0-beta.1                                ...           8 years ago
  • 4.9.0                                ...           8 years ago
  • 5.0.0-beta.0                                ...           8 years ago
  • 4.8.2                                ...           8 years ago
  • 4.8.1                                ...           8 years ago
  • 4.8.0                                ...           8 years ago
  • 4.7.7                                ...           8 years ago
  • 4.7.6                                ...           8 years ago
  • 4.7.5                                ...           8 years ago
  • 4.7.4                                ...           8 years ago
  • 4.7.3                                ...           8 years ago
  • 4.7.2                                ...           8 years ago
  • 4.7.1                                ...           8 years ago
  • 4.7.0                                ...           8 years ago
  • 4.6.1                                ...           8 years ago
  • 4.6.0                                ...           8 years ago
  • 4.5.0                                ...           8 years ago
  • 4.4.1                                ...           8 years ago
  • 4.4.0                                ...           8 years ago
  • 4.3.1                                ...           8 years ago
  • 4.3.0                                ...           8 years ago
  • 4.2.0                                ...           8 years ago
  • 4.1.8                                ...           8 years ago
  • 4.1.7                                ...           8 years ago
  • 4.1.6                                ...           8 years ago
  • 4.1.5                                ...           8 years ago
  • 4.1.4                                ...           8 years ago
  • 4.1.3                                ...           8 years ago
  • 4.1.2                                ...           8 years ago
  • 4.1.1                                ...           8 years ago
  • 4.1.0                                ...           8 years ago
  • 4.0.6                                ...           8 years ago
  • 4.0.5                                ...           9 years ago
  • 4.0.4                                ...           9 years ago
  • 4.0.3                                ...           9 years ago
  • 4.0.2                                ...           9 years ago
  • 4.0.1                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.8.10                                ...           9 years ago
  • 3.8.9                                ...           9 years ago
  • 3.8.8                                ...           9 years ago
  • 3.8.7                                ...           9 years ago
  • 3.8.6                                ...           9 years ago
  • 3.8.5                                ...           9 years ago
  • 3.8.4                                ...           9 years ago
  • 3.8.3                                ...           9 years ago
  • 3.8.2                                ...           9 years ago
  • 3.8.1                                ...           9 years ago
  • 3.8.0                                ...           9 years ago
  • 3.7.2                                ...           9 years ago
  • 3.7.1                                ...           9 years ago
  • 3.7.0                                ...           9 years ago
  • 3.6.2                                ...           9 years ago
  • 3.6.1                                ...           9 years ago
  • 3.6.0                                ...           9 years ago
  • 3.5.3                                ...           9 years ago
  • 3.5.2                                ...           9 years ago
  • 3.5.1                                ...           9 years ago
  • 3.5.0                                ...           9 years ago
  • 3.4.0                                ...           9 years ago
  • 3.3.1                                ...           9 years ago
  • 3.3.0                                ...           9 years ago
  • 3.2.3                                ...           9 years ago
  • 3.2.2                                ...           9 years ago
  • 3.2.1                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.1                                ...           9 years ago
  • 3.1.0                                ...           9 years ago
  • 3.0.4                                ...           9 years ago
  • 3.0.3                                ...           9 years ago
  • 3.0.2                                ...           9 years ago
  • 3.0.1                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.5.0                                ...           9 years ago
  • 2.4.0                                ...           9 years ago
  • 2.3.0                                ...           9 years ago
  • 2.2.2                                ...           9 years ago
  • 2.2.1                                ...           9 years ago
  • 2.2.0                                ...           9 years ago
  • 2.1.4                                ...           9 years ago
  • 2.1.3                                ...           9 years ago
  • 2.1.2                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.4                                ...           9 years ago
  • 2.0.3                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 2.0.0-beta.3                                ...           9 years ago
  • 2.0.0-beta.2                                ...           9 years ago
  • 1.4.10                                ...           9 years ago
  • 2.0.0-beta.1                                ...           9 years ago
  • 2.0.0-beta.0                                ...           9 years ago
  • 1.4.9                                ...           9 years ago
  • 1.4.8                                ...           9 years ago
  • 1.4.7                                ...           9 years ago
  • 1.4.6                                ...           9 years ago
  • 1.4.5                                ...           9 years ago
  • 1.4.4                                ...           9 years ago
  • 1.4.3                                ...           9 years ago
  • 1.4.2                                ...           9 years ago
  • 1.4.1                                ...           9 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.2                                ...           9 years ago
  • 1.3.1                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.7.2                                ...           9 years ago
  • 0.7.1                                ...           9 years ago
  • 0.7.0                                ...           9 years ago
  • 0.6.15                                ...           9 years ago
  • 0.6.14                                ...           9 years ago
  • 0.6.13                                ...           9 years ago
  • 0.6.12                                ...           9 years ago
  • 0.6.11                                ...           9 years ago
  • 0.6.10                                ...           9 years ago
  • 0.6.9                                ...           9 years ago
  • 0.6.8                                ...           9 years ago
  • 0.6.7                                ...           9 years ago
  • 0.6.6                                ...           9 years ago
  • 0.6.5                                ...           9 years ago
  • 0.6.4                                ...           9 years ago
  • 0.6.3                                ...           9 years ago
  • 0.6.2                                ...           9 years ago
  • 0.6.1                                ...           9 years ago
  • 0.6.0                                ...           9 years ago
  • 0.5.12                                ...           9 years ago
  • 0.5.11                                ...           9 years ago
  • 0.5.10                                ...           9 years ago
  • 0.5.9                                ...           9 years ago
  • 0.5.8                                ...           9 years ago
  • 0.5.7                                ...           9 years ago
  • 0.5.6                                ...           9 years ago
  • 0.5.5                                ...           9 years ago
  • 0.5.4                                ...           9 years ago
  • 0.5.3                                ...           9 years ago
  • 0.5.2                                ...           9 years ago
  • 0.5.0                                ...           9 years ago
  • 0.4.15                                ...           9 years ago
  • 0.4.14                                ...           9 years ago
  • 0.4.12                                ...           9 years ago
  • 0.4.10                                ...           9 years ago
  • 0.4.9                                ...           9 years ago
  • 0.4.8                                ...           9 years ago
  • 0.4.7                                ...           9 years ago
  • 0.4.6                                ...           9 years ago
  • 0.4.5                                ...           9 years ago
  • 0.4.4                                ...           9 years ago
  • 0.4.3                                ...           9 years ago
  • 0.4.2                                ...           9 years ago
  • 0.4.1                                ...           9 years ago
  • 0.4.0                                ...           9 years ago
  • 0.3.12                                ...           9 years ago
  • 0.3.11                                ...           9 years ago
  • 0.3.8                                ...           9 years ago
  • 0.3.7                                ...           9 years ago
  • 0.3.6                                ...           9 years ago
  • 0.3.5                                ...           9 years ago
  • 0.3.4                                ...           9 years ago
  • 0.3.3                                ...           9 years ago
  • 0.3.2                                ...           9 years ago
  • 0.3.1                                ...           9 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.9                                ...           9 years ago
  • 0.2.8                                ...           9 years ago
  • 0.2.7                                ...           9 years ago
  • 0.2.6                                ...           9 years ago
  • 0.2.5                                ...           9 years ago
  • 0.2.4                                ...           9 years ago
  • 0.2.3                                ...           9 years ago
  • 0.2.2                                ...           9 years ago
  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.16                                ...           9 years ago
  • 0.1.15                                ...           9 years ago
  • 0.1.14                                ...           9 years ago
  • 0.1.13                                ...           9 years ago
  • 0.1.12                                ...           9 years ago
  • 0.1.11                                ...           9 years ago
  • 0.1.10                                ...           9 years ago
  • 0.1.9                                ...           9 years ago
  • 0.1.8                                ...           9 years ago
  • 0.1.7                                ...           9 years ago
  • 0.1.6                                ...           9 years ago
  • 0.1.5                                ...           9 years ago
  • 0.1.4                                ...           9 years ago
  • 0.1.3                                ...           9 years ago
  • 0.1.2                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
  • 0.0.12                                ...           9 years ago
  • 0.0.11                                ...           9 years ago
  • 0.0.10                                ...           9 years ago
  • 0.0.9                                ...           9 years ago
  • 0.0.8                                ...           9 years ago
  • 0.0.7                                ...           9 years ago
  • 0.0.6                                ...           9 years ago
  • 0.0.5                                ...           9 years ago
  • 0.0.4                                ...           9 years ago
Maintainers (2)
Downloads
Total 22
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (4)
Dev Dependencies (33)

© 2010 - cnpmjs.org x YWFE | Home | YWFE