ajv README

The project's README from github.com/ajv-validator/ajv. As one markdown file: README.md.

Ajv logo

 

Ajv JSON schema validator

The fastest JSON validator for Node.js and browser.

Supports JSON Schema draft-04/06/07/2019-09/2020-12 (draft-04 support requires ajv-draft-04 package) and JSON Type Definition RFC8927.

build npm npm downloads Coverage Status SimpleX Gitter GitHub Sponsors

Ajv sponsors

Mozilla

Microsoft

RetoolTideliftSimpleX

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.

Please review Contributing guidelines and Code components.

Documentation

All documentation is available on the Ajv website.

Some useful site links:

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 8:

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 schema = {
  type: "object",
  properties: {
    foo: {type: "integer"},
    bar: {type: "string"},
  },
  required: ["foo"],
  additionalProperties: false,
}

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

const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) console.log(validate.errors)

Learn how to use Ajv and see more examples in the Guide: getting started

Changes history

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

Please note: Changes in version 8.0.0

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 [email protected] - 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

ajv (ajv-validator/ajv)

Searching Database…

14.9K ·GitHub
这是什么?Ajv 是一个 JavaScript 的 JSON 模式校验器:给它一个 schema,它就能检查你的 JSON 数据是否符合要求。它号称速度最快,支持 JSON Schema 的 draft-04 到 2020-12 各个版本,还支持 JSON Type Definition(RFC 8927)。
那它是引入到代码里的库,还是一个独立的应用?是一个库,不是应用:你需要把它接入自己的 JavaScript 或 TypeScript 代码里。文档里也介绍了命令行工具的用法,以及如何生成独立的校验代码。
我怎么在自己的项目里开始用它?先从 npm 安装,然后在 JavaScript 代码里调用它。README 建议直接在 Node.js 的交互式环境(REPL)里试用,Ajv 官网上的入门指南会带你走完剩下的步骤。
除了 Node.js 和 npm,我还需要装别的东西吗?不需要:它是纯 TypeScript 写的,只依赖四个很小的 JS 包(fast-deep-equal、fast-uri、json-schema-traverse、require-from-string),不用编译任何本地组件,也不需要额外安装工具。
升级到新的大版本会很麻烦吗?要预留一些迁移工作:更新日志里标出了每个大版本的重要改动,升级前建议先看看 8.0.0、7.0.0 和 6.0.0 这几个版本的说明。
用在商业项目里免费吗?免费:Ajv 采用 MIT 许可证,商用没有问题;需要付费技术支持的公司可以通过 Tidelift 订阅获得。
JSON Type Definition 是什么,Ajv 为什么还要支持它?它是一种更简单的模式语言,已被标准化为 RFC 8927。Ajv 除了支持 JSON Schema,也能按它来校验数据,文档网站上还有一页专门对比两者,帮你做选择。
公司在用 Ajv 时能拿到商业技术支持吗?可以。Ajv 包含在 Tidelift 订阅里,公司除了软件维护者本身提供的支持之外,还能获得统一的集中式支持。
Ajv 现在还在活跃开发吗?是的。作者正在为开发和维护下一个大版本筹集资金,已经有 40 位个人和 6 个组织通过 GitHub 和 OpenCollective 赞助了这项工作,这也帮助项目拿到了 MOSS 补助金。
Size
38.1 MB
Stars
14.9K
Age
11y
Commits · 90 Days