Registry / devops / ajv-cli

ajv-cli

JSON →
library5.0.0jsnpmunverified

Command-line interface for Ajv, a fast JSON Schema validator. Stable version 5.0.0. Supports JSON, JSON5, and YAML data files. Allows validation, compilation, migration, and testing of JSON schemas across drafts (draft-07, 2019-09, 2020-12) and JSON Type Definition. Configurable error output formats and custom keywords. Integrates with ts-node for TypeScript custom modules. Differentiates via Ajv's speed and multi-format input.

npm install ajv-cli
INSTALL
IMPORT
SIG · AJV-CLI
A
ajv-cli
devopsjavascriptv5.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cli
npx ajv-cli validate -s schema.json -d data.json
ajv-cli is a CLI tool, not a library. Use via command line, not import.
options
ajv validate -s schema.json -d data.json --spec=draft2020 --errors=text
ajv --errors text -s schema.json -d data.json
Options like --errors and --spec must be placed after the command (validate) or before for global ones; order matters.
custom keywords
ajv validate -s schema.json -d data.json -c ./custom-keywords.js
ajv validate -s schema.json -d data.json -c custom-keywords
Custom keyword file path should be relative (starting with ./) or a package name; bare file name without extension may fail.

Installs ajv-cli globally, creates a JSON schema and data files, then validates data.

npm install -g ajv-cli cat > schema.json <<EOF { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "number", "minimum": 0 } }, "required": ["name"] } EOF cat > data.json <<EOF {"name": "Alice", "age": 30} EOF ajv validate -s schema.json -d data.json # Exit code 0, no output means valid # Test invalid data: echo '{"name": "Bob", "age": -1}' > invalid.json ajv validate -s schema.json -d invalid.json # Output: data must be >= 0, exit code 1
Debug
Known issues
breakingajv-cli v5.0.0 drops support for Node.js < 14; uses ESM-based Ajv v8.
fix
Upgrade to Node.js 14 or later.
affects: >=5.0.0
deprecated--spec=draft6 is deprecated; use --spec=draft7 or later.
fix
Update to --spec=draft7 or later version.
affects: <5.0.0
gotchaGlob patterns in -r or -d must be quoted to prevent shell expansion.
fix
Use quotes: ajv -s schema.json -d "data/*.json"
affects: all
gotchaFile extensions cannot be omitted in glob patterns for -r or -d; only -s allows extension omission.
fix
Include .json extension in globs: -d "data/*.json"
affects: all
gotchaCustom keyword modules with TypeScript require ts-node peer dependency; without it, .ts files fail.
fix
Install ts-node: npm install --global ts-node
affects: >=5.0.0
gotchaThe -c option for custom keywords expects a path starting with './' for relative files; otherwise treated as package name.
fix
Use -c ./my-keywords.js for local files.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'ts-node'
Missing optional peer dependency ts-node when using TypeScript custom keywords.
fix
Install ts-node: npm install -g ts-node
data must be object
Data file contains JSON array at top level while schema expects an object.
fix
Wrap data in an object or adjust schema to accept array.
schema is invalid: data must NOT have additional properties
Schema contains 'additionalProperties: false' but data has extra keys.
fix
Remove extra properties from data or remove 'additionalProperties' from schema.
Error: ENOENT: no such file or directory, open 'schema.json'
File path is incorrect or file missing.
fix
Provide correct path to schema file, or check current working directory.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
ts-nodeoptionalOptional peer dependency needed to run TypeScript custom keywords modules; install >=9.0.0 for TypeScript support.
Agent activity
57 hits · last 30 days
node
52
OpenAI (training)
1
Resources