Need help with ajv-cli?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

175 Stars 43 Forks MIT License 180 Commits 44 Opened issues


Command-line interface for Ajv JSON Validator

Services available


Need anything else?

Contributors list


Command line interface for ajv, one of the fastest json schema validators. Supports JSON, JSON5, and YAML.

build npm coverage gitter



npm install -g ajv-cli

JSON schema language and version


can be used with all commands (other than help) to choose JSON schema language:
  • --spec=draft7
    (default) - support JSON Schema draft-07 (uses
    import Ajv from "ajv"
  • --spec=draft2019
    - support JSON Schema draft-2019-09 (uses
    import Ajv from "ajv/dist/2019"
  • --spec=draft2020
    - support JSON Schema draft-2020-12 (uses
    import Ajv from "ajv/dist/2020"
  • --spec=jtd
    - support JSON Type Definition (uses
    import Ajv from "ajv/dist/jtd"


Help command

ajv help
ajv help validate
ajv help compile
ajv help migrate
ajv help test

Validate data

This command validates data files against JSON-schema

ajv validate -s test/schema.json -d test/valid_data.json
ajv -s test/schema.json -d test/valid_data.json

You can omit

command name and
from the input file names.


- file name of JSON-schema

Only one schema can be passed in this parameter

- JSON data

Multiple data files can be passed, as in

ajv -s test/schema.json -d "test/valid*.json"

If some file is invalid exit code will be 1.

- referenced schemas

The schema in

parameter can reference any of these schemas with

Multiple schemas can be passed both by using this parameter multiple times and with glob patterns. Glob pattern should be quoted and extensions cannot be omitted.

- meta-schemas

Schemas can use any of these schemas as a meta-schema (that is the schema used in

keyword - it is used to validate the schema itself).

Multiple meta-schemas can be passed, as in

- custom keywords/formats definitions

You can pass module(s) that define custom keywords/formats. The modules should export a function that accepts Ajv instance as a parameter. The file name should start with ".", it will be resolved relative to the current folder. The package name can also be passed - it will be used in require as is. These modules can be written in TypeScript if you have


For example, you can use

-c ajv-keywords
to add all keywords from ajv-keywords package or
-c ajv-keywords/keywords/typeof
to add only typeof keyword.


  • --errors=
    : error reporting format. Possible values:
    • js
      (default): JavaScript object
    • json
      : JSON with indentation and line-breaks
    • line
      : JSON without indentation/line-breaks (for easy parsing)
    • text
      : human readable error messages with data paths
  • --changes=
    : detect changes in data after validation.
    Data can be modified with Ajv options
    The changes are reported in JSON-patch format (RFC6902).
    Possible values are

Compile schemas

This command validates and compiles schema without validating any data.

It can be used to check that the schema is valid and to create a standalone module exporting validation function(s).

ajv compile -s schema

compile to module file

ajv compile -s schema -o validate.js

compile to stdout, to allow code formatting (js-beautify has to be installed separately)

ajv compile -s schema -o | js-beautify > validate.js


- file name(s) of JSON-schema(s)

Multiple schemas can be passed both by using this parameter multiple times and with glob patterns.

ajv compile -s "test/schema*.json"
- output file for compiled validation function module

If multiple schemas are compiled with this option the module will have multiple exports named as schema $id's or as file names, otherwise the module will export validation function as default export.

ajv compile -s "schema.json" -o "validate_schema.js"

without parameter should be used to output code to stdout to pass it to some code formatter.

This command also supports parameters

as in validate command.

Migrate schemas

This command validates and migrates schema from JSON Schema draft-04 to draft-07, draft-2019-09 or draft-2020-12 using json-schema-migrate package.

The version of JSON Schema is determined by

parameter (only
ajv migrate -s schema

compile to specific file name

ajv migrate -s schema -o migrated_schema.json


- file name(s) of JSON-schema(s)

Multiple schemas can be passed both by using this parameter multiple times and with glob patterns.

ajv migrate -s "test/schema*.json"

If parameter

is not specified the migrated schema is written to the same file and the original file is preserved with

If migration doesn't change anything in the schema file no changes in files are made.

- output file for migrated schema

Only a single schema can be migrated with this option.

ajv compile -s "schema.json" -o migrated_schema.json


  • --indent=
    : indentation in migrated schema JSON file, 4 by default
  • --validate-schema=false
    : skip schema validation

Test validation result

This command asserts that the result of the validation is as expected.

ajv test -s test/schema.json -d test/valid_data.json --valid
ajv test -s test/schema.json -d test/invalid_data.json --invalid

If the option

) is used for the
to pass (exit code 0) the data file(s) should be valid (invalid).

This command supports the same options and parameters as validate with the exception of


Ajv options

You can pass the following Ajv options:

| Option | Description | | ------ | ----------- | | Strict mode | |

- set all strict mode restrictions | |
| log on (
) or ignore (
) strict restrictions (the default is to log) | |
| throw on (
) or ignore (
) strict schema restrictions (the default is to throw) | |
| throw on (
) or ignore (
) strict types restrictions (the default is to log) | |
| throw on (
) or log (
) required properties restrictions (the default is to ignore) | |
| allow
matching patterns in
| |
| allow union types | |
| disable format validation | | Validation and reporting | |
| use $data references | |
| collect all validation errors | |
| include schema and data in errors | |
| log schema
s | |
| referenced schemas compilation mode (true/false/<number>) | | Modify validated data | |
| remove additional properties (true/all/failing) | |
| replace missing properties/items with the values from default keyword | |
| change type of data to match type keyword | | Advanced | |
| precision of multipleOf, pass integer number | |
| do not include text messages in errors | |
| max size of
to compile to expression (rather than to loop) | |
| max size of
to compile to expression (rather than to loop) | |
| only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) | | Code generation | |
| generate ES5 code | |
| generate multi-line code | |
| disable optimization (
) or number of optimization passes (1 pass by default) | |
| code to require formats object (only needed if you generate standalone code and do not use ajv-formats) |

Options can be passed using either dash-case or camelCase.

See Ajv Options for more information.

Version History




We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.