# Ajv vs Zod: どちらのバリデーション手法を選ぶか

> Ajv vs Zod: 高速なJSON Schemaバリデータ vs 推論を備えたTypeScript-firstのスキーマライブラリ。標準、パフォーマンス、DX、CI/テストへの適合を率直に比較。

Source: https://latchkey.dev/ja/learn/tool-comparisons/ajv-vs-zod  
Updated: 2026-06-26

AjvはJSON Schemaに対して高いパフォーマンスで検証し、ZodはTypeScriptでスキーマを定義して静的な型を推論します。

AjvはJSON Schemaを高速なバリデータへコンパイルするため、すでにJSON Schema標準(OpenAPI、設定の検証、相互運用)を使っていて最大限のスループットが必要な場合に理想的です。ZodはスキーマをTypeScriptのコードとして定義し、静的な型を推論して優れたDXを提供しますが、標準ベースではなく、一般にコンパイルされたAjvより遅いです。AjvはJSON Schema標準と生の速度で優れ、ZodはTypeScript-firstのDXと型推論で優れます。

## Comparison

|  | Ajv | Zod |
| --- | --- | --- |
| 標準 | JSON Schema | TypeScriptネイティブ |
| 型推論 | ツール経由 | 組み込み (z.infer) |
| パフォーマンス | 非常に高速(コンパイル済み) | より遅い |
| 相互運用 | 広い(OpenAPI、設定) | TS中心 |
| 最適な用途 | JSON Schema、高スループット | TypeScript-firstのDX |

## ユースケースと標準

Ajvは、JSON Schema上に構築されたシステム、OpenAPI駆動の検証、または最大限の検証スループットが必要なホットパスに適しています。Zodは、優れたDXとともに一つの定義からスキーマと型を得たいTypeScriptアプリに適しています。両者は異なる優先事項に応えます。標準/パフォーマンス vs 型推論とエルゴノミクスです。

## テストとCI

どちらも決定論的に検証し、Ajvのコンパイル済みバリデータとZodのスキーマはきれいにunit testできます。いずれもmanaged runnerで動作し、高速なrunnerはバリデーションのテストスイートを短縮します。

## Decide with your own numbers, not a feature table

Feature comparisons age badly and rarely decide anything, because both tools in a mature category can do the job. What differs is how each behaves on your repository, and that takes one afternoon to measure.

```Terminal
# time a cold install with each candidate, cache cleared
hyperfine --prepare "rm -rf node_modules" --warmup 1 \
  "<tool-a> install" "<tool-b> install"

# and the thing CI actually pays for: a cold run with no local cache
docker run --rm -v "$(pwd):/w" -w /w node:22 sh -c "<tool> install"
```

> Measure the cold path. Warm local benchmarks favour whichever tool you already have cached, which is exactly the condition a CI runner never has.

## What actually changes when you switch

- Lockfile format. A switch is a one-way door for anyone still on the old tool until everyone migrates, so plan it as a single coordinated change.
- Resolution strictness. Tools differ on whether an undeclared transitive import works, and the stricter one will surface latent bugs as new failures.
- CI cache configuration. The cache path and key differ per tool; carrying over the old ones silently disables caching.
- Everyone on the team and every runner must move together. Pin the version so they cannot drift.

## 結論

JSON Schema、OpenAPI、または高スループットの検証を扱うなら: Ajv。推論された型とエルゴノミックなスキーマでTypeScript-firstに構築するなら: Zod。Ajvは標準と速度で、ZodはTypeScriptのDXで優れます。

## FAQ

### Ajv vs Zod: Which Validation Approach?

Ajv compiles JSON Schema into fast validators, making it ideal when you already use the JSON Schema standard (OpenAPI, config validation, interop) and need maximum throughput. Zod defines schemas as TypeScript code, inferring static types and offering excellent DX, but is not standards-based and is generally slower than compiled Ajv.

### Use case and standards?

Ajv suits systems built on JSON Schema, OpenAPI-driven validation, or hot paths needing maximum validation throughput. Zod suits TypeScript apps wanting schemas and types from one definition with great DX. They serve different priorities: standards/performance vs type inference and ergonomics.

### Testing and CI?

Both validate deterministically; Ajv's compiled validators and Zod's schemas unit test cleanly. Either runs on managed runners, where faster runners shorten validation test suites.

### Which should I choose?

Working with JSON Schema, OpenAPI, or high-throughput validation: Ajv. Building TypeScript-first with inferred types and ergonomic schemas: Zod. Ajv wins on standards and speed; Zod wins on TypeScript DX.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
