ajv vs joi vs jsonschema vs yup vs z-schema
データバリデーションライブラリ
ajvjoijsonschemayupz-schema類似パッケージ:

データバリデーションライブラリ

データバリデーションライブラリは、アプリケーションのデータが特定のルールや形式に従っていることを確認するために使用されます。これにより、データの整合性が保たれ、エラーや不正なデータの処理を防ぐことができます。これらのライブラリは、JSONデータの検証、スキーマの定義、エラーメッセージの生成などの機能を提供します。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
ajv014,6691.03 MB3242ヶ月前MIT
joi021,201585 kB1884日前BSD-3-Clause
jsonschema01,86983.5 kB711年前MIT
yup023,689270 kB2406ヶ月前MIT
z-schema03421.05 MB02日前MIT

機能比較: ajv vs joi vs jsonschema vs yup vs z-schema

パフォーマンス

  • ajv:

    AJVは、非常に高速なJSONスキーマバリデーションを提供します。特に、大量のデータを処理する際に、そのパフォーマンスの高さが際立ちます。

  • joi:

    Joiは、パフォーマンスは良好ですが、AJVほどではありません。シンプルなスキーマ定義に適していますが、複雑なバリデーションには注意が必要です。

  • jsonschema:

    jsonschemaは、標準に準拠したバリデーションを提供しますが、パフォーマンスはAJVに劣ります。

  • yup:

    Yupは、非同期バリデーションをサポートしていますが、パフォーマンスは他のライブラリに比べてやや遅い場合があります。

  • z-schema:

    Z-Schemaは、柔軟性が高いですが、パフォーマンスはAJVに比べて劣ることがあります。

APIの使いやすさ

  • ajv:

    AJVは、設定が簡単で、JSONスキーマを使ったバリデーションが直感的に行えます。

  • joi:

    Joiは、非常にシンプルで直感的なAPIを提供し、オブジェクトのスキーマを簡単に定義できます。

  • jsonschema:

    jsonschemaは、標準的なJSONスキーマに基づいているため、使い慣れた開発者には扱いやすいですが、APIはやや冗長です。

  • yup:

    Yupは、PromiseベースのAPIを提供し、非同期処理を簡単に扱えます。

  • z-schema:

    Z-Schemaは、柔軟なスキーマ定義が可能ですが、APIは他のライブラリに比べて複雑さがあります。

エラーメッセージのカスタマイズ

  • ajv:

    AJVは、エラーメッセージをカスタマイズするためのオプションを提供していますが、設定が少し複雑です。

  • joi:

    Joiは、エラーメッセージのカスタマイズが非常に簡単で、開発者にとって使いやすいです。

  • jsonschema:

    jsonschemaは、エラーメッセージのカスタマイズ機能が限られています。

  • yup:

    Yupは、エラーメッセージを簡単にカスタマイズでき、特にフォームバリデーションに便利です。

  • z-schema:

    Z-Schemaは、エラーメッセージのカスタマイズが可能ですが、他のライブラリに比べてやや複雑です。

非同期バリデーションのサポート

  • ajv:

    AJVは、非同期バリデーションをサポートしていません。

  • joi:

    Joiは、非同期バリデーションをサポートしており、Promiseを返すことができます。

  • jsonschema:

    jsonschemaは、非同期バリデーションをサポートしていません。

  • yup:

    Yupは、非同期バリデーションをサポートしており、特にReactアプリケーションでの使用に適しています。

  • z-schema:

    Z-Schemaは、非同期バリデーションをサポートしていません。

拡張性

  • ajv:

    AJVは、プラグインを使用して機能を拡張することができます。

  • joi:

    Joiは、カスタムバリデーションメソッドを簡単に追加でき、拡張性があります。

  • jsonschema:

    jsonschemaは、標準に準拠しているため、拡張性は限られています。

  • yup:

    Yupは、カスタムバリデーションを簡単に追加でき、拡張性があります。

  • z-schema:

    Z-Schemaは、非常に柔軟で拡張性が高いですが、設定が複雑になることがあります。

選び方: ajv vs joi vs jsonschema vs yup vs z-schema

  • ajv:

    AJVは、高速なJSONスキーマバリデーションを必要とする場合に最適です。特に、パフォーマンスが重要なアプリケーションや、大量のデータを扱う場合に適しています。

  • joi:

    Joiは、シンプルで直感的なAPIを持ち、オブジェクトのスキーマを定義するのが容易です。特に、Node.jsアプリケーションでのデータバリデーションに適しています。

  • jsonschema:

    jsonschemaは、JSONスキーマに準拠したバリデーションを行うためのライブラリで、標準に従ったバリデーションが必要な場合に選択します。

  • yup:

    Yupは、Promiseベースのバリデーションをサポートしており、非同期バリデーションが必要な場合に適しています。特に、Reactアプリケーションでのフォームバリデーションに便利です。

  • z-schema:

    Z-Schemaは、柔軟なスキーマ定義と拡張性を提供します。特に、複雑なスキーマやカスタムバリデーションが必要な場合に選択します。

ajv のREADME

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