{"id":13903197,"url":"https://github.com/ajv-validator/ajv-cli","last_synced_at":"2025-05-15T17:05:44.410Z","repository":{"id":35227607,"uuid":"39486873","full_name":"ajv-validator/ajv-cli","owner":"ajv-validator","description":"Command-line interface for Ajv JSON Validator","archived":false,"fork":false,"pushed_at":"2024-07-30T17:52:31.000Z","size":197,"stargazers_count":283,"open_issues_count":90,"forks_count":71,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-05T03:47:13.355Z","etag":null,"topics":["ajv","command-line","json-schema","validator"],"latest_commit_sha":null,"homepage":"https://ajv.js.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajv-validator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"epoberezkin","open_collective":"ajv"}},"created_at":"2015-07-22T05:12:28.000Z","updated_at":"2025-04-30T23:43:33.000Z","dependencies_parsed_at":"2024-11-21T02:00:17.348Z","dependency_job_id":null,"html_url":"https://github.com/ajv-validator/ajv-cli","commit_stats":{"total_commits":142,"total_committers":19,"mean_commits":7.473684210526316,"dds":0.5422535211267605,"last_synced_commit":"58d6f074720d5dc0773c3786320b7d35718060cd"},"previous_names":["jessedc/ajv-cli"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajv-validator%2Fajv-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajv-validator%2Fajv-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajv-validator%2Fajv-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajv-validator%2Fajv-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajv-validator","download_url":"https://codeload.github.com/ajv-validator/ajv-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajv","command-line","json-schema","validator"],"created_at":"2024-08-06T22:01:49.829Z","updated_at":"2025-05-15T17:05:39.399Z","avatar_url":"https://github.com/ajv-validator.png","language":"TypeScript","readme":"# ajv-cli\n\nCommand line interface for [ajv](https://github.com/epoberezkin/ajv), one of the [fastest json schema validators](https://github.com/ebdrup/json-schema-benchmark).\nSupports [JSON](http://json.org/), [JSON5](http://json5.org/), and [YAML](http://yaml.org/).\n\n[![build](https://github.com/ajv-validator/ajv-cli/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv-cli/actions?query=workflow%3Abuild)\n[![npm](https://img.shields.io/npm/v/ajv-cli.svg)](https://www.npmjs.com/package/ajv-cli)\n[![coverage](https://coveralls.io/repos/github/ajv-validator/ajv-cli/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv-cli?branch=master)\n[![gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)\n\n## Contents\n\n- [Installation](#installation)\n- [JSON schema version](#json-schema-version)\n- Commands\n  - [Help](#help-command)\n  - [Validate data](#validate-data)\n  - [Compile schemas](#compile-schemas)\n  - [Migrate schemas](#migrate-schemas)\n  - [Test validation result](#test-validation-result)\n- [Ajv options](#ajv-options)\n- [Version History, License](#version_history)\n\n## Installation\n\n```sh\nnpm install -g ajv-cli\n```\n\n## JSON schema language and version\n\nParameter `--spec` can be used with all commands (other than help) to choose JSON schema language:\n\n- `--spec=draft7` (default) - support JSON Schema draft-07 (uses `import Ajv from \"ajv\"`)\n- `--spec=draft2019` - support JSON Schema draft-2019-09 (uses `import Ajv from \"ajv/dist/2019\"`)\n- `--spec=draft2020` - support JSON Schema draft-2020-12 (uses `import Ajv from \"ajv/dist/2020\"`)\n- `--spec=jtd` - support [JSON Type Definition](https://ajv.js.org/json-type-definition.html) (uses `import Ajv from \"ajv/dist/jtd\"`)\n\n## Commands\n\n### Help command\n\n```sh\najv help\najv help validate\najv help compile\najv help migrate\najv help test\n```\n\n### Validate data\n\nThis command validates data files against JSON-schema\n\n```sh\najv validate -s test/schema.json -d test/valid_data.json\najv -s test/schema.json -d test/valid_data.json\n```\n\nYou can omit `validate` command name and `.json` from the [input file names](https://nodejs.org/api/modules.html#modules_file_modules).\n\n#### Parameters\n\n##### `-s` - file name of JSON-schema\n\nOnly one schema can be passed in this parameter\n\n##### `-d` - JSON data\n\nMultiple data files can be passed, as in `-r` parameter:\n\n```sh\najv -s test/schema.json -d \"test/valid*.json\"\n```\n\nIf some file is invalid exit code will be 1.\n\n##### `-r` - referenced schemas\n\nThe schema in `-s` parameter can reference any of these schemas with `$ref` keyword.\n\nMultiple schemas can be passed both by using this parameter multiple times and with [glob patterns](https://github.com/isaacs/node-glob#glob-primer). Glob pattern should be quoted and extensions cannot be omitted.\n\n##### `-m` - meta-schemas\n\nSchemas can use any of these schemas as a meta-schema (that is the schema used in `$schema` keyword - it is used to validate the schema itself).\n\nMultiple meta-schemas can be passed, as in `-r` parameter.\n\n##### `-c` - custom keywords/formats definitions\n\nYou 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.\nThese modules can be written in TypeScript if you have `ts-node` installed.\n\nFor example, you can use `-c ajv-keywords` to add all keywords from [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package or `-c ajv-keywords/keywords/typeof` to add only typeof keyword.\n\n#### Options\n\n- `--errors=`: error reporting format. Possible values:\n\n  - `js` (default): JavaScript object\n  - `json`: JSON with indentation and line-breaks\n  - `line`: JSON without indentation/line-breaks (for easy parsing)\n  - `text`: human readable error messages with data paths\n\n- `--changes=`: detect changes in data after validation.\u003cbr\u003e\n  Data can be modified with [Ajv options](#ajv-options) `--remove-additional`, `--use-defaults` and `--coerce-types`).\u003cbr\u003e\n  The changes are reported in JSON-patch format ([RFC6902](https://tools.ietf.org/html/rfc6902)).\u003cbr\u003e\n  Possible values are `js` (default), `json` and `line` (see `--errors` option).\n\n### Compile schemas\n\nThis command validates and compiles schema without validating any data.\n\nIt can be used to check that the schema is valid and to create a standalone module exporting validation function(s).\n\n```sh\najv compile -s schema\n\n# compile to module file\najv compile -s schema -o validate.js\n\n## compile to stdout, to allow code formatting (js-beautify has to be installed separately)\najv compile -s schema -o | js-beautify \u003e validate.js\n```\n\n#### Parameters\n\n##### `-s` - file name(s) of JSON-schema(s)\n\nMultiple schemas can be passed both by using this parameter multiple times and with [glob patterns](https://github.com/isaacs/node-glob#glob-primer).\n\n```sh\najv compile -s \"test/schema*.json\"\n```\n\n##### `-o` - output file for compiled validation function module\n\nIf 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.\n\n```sh\najv compile -s \"schema.json\" -o \"validate_schema.js\"\n```\n\n`-o` without parameter should be used to output code to stdout to pass it to some code formatter.\n\nThis command also supports parameters `-r`, `-m` and `-c` as in [validate](#validate-data) command.\n\n### Migrate schemas\n\nThis command validates and migrates schema from JSON Schema draft-04 to draft-07, draft-2019-09 or draft-2020-12 using [json-schema-migrate](https://github.com/ajv-validator/json-schema-migrate) package.\n\nThe [version of JSON Schema](#json-schema-version) is determined by `--spec` parameter (only `\"draft7\"`, `\"draft2019\"` or  `\"draft2020\"`).\n\n```sh\najv migrate -s schema\n\n# compile to specific file name\najv migrate -s schema -o migrated_schema.json\n```\n\n#### Parameters\n\n##### `-s` - file name(s) of JSON-schema(s)\n\nMultiple schemas can be passed both by using this parameter multiple times and with [glob patterns](https://github.com/isaacs/node-glob#glob-primer).\n\n```sh\najv migrate -s \"test/schema*.json\"\n```\n\nIf parameter `-o` is not specified the migrated schema is written to the same file and the original file is preserved with `.bak` extension.\n\nIf migration doesn't change anything in the schema file no changes in files are made.\n\n##### `-o` - output file for migrated schema\n\nOnly a single schema can be migrated with this option.\n\n```sh\najv compile -s \"schema.json\" -o migrated_schema.json\n```\n\n#### Options\n\n- `--indent=`: indentation in migrated schema JSON file, 4 by default\n- `--validate-schema=false`: skip schema validation\n\n### Test validation result\n\nThis command asserts that the result of the validation is as expected.\n\n```sh\najv test -s test/schema.json -d test/valid_data.json --valid\najv test -s test/schema.json -d test/invalid_data.json --invalid\n```\n\nIf the option `--valid` (`--invalid`) is used for the `test` to pass (exit code 0) the data file(s) should be valid (invalid).\n\nThis command supports the same options and parameters as [validate](#validate-data) with the exception of `--changes`.\n\n## Ajv options\n\nYou can pass the following [Ajv options](https://ajv.js.org/options.html):\n\n| Option | Description |\n| ------ | ----------- |\n| Strict mode |\n| `--strict=`| `true`/`false`/`log` - set all [strict mode](https://ajv.js.org/strict-mode.html) restrictions |\n| `--strict-schema=`| log on (`log`) or ignore (`false`) [strict ](https://ajv.js.org/strict-mode.html#prohibit-ignored-keywords) restrictions (the default is to log) |\n| `--strict-tuples=`| throw on (`true`) or ignore (`false`) [strict schema](https://ajv.js.org/strict-mode.html#prohibit-unconstrained-tuples) restrictions (the default is to throw) |\n| `--strict-types=`| throw on (`true`) or ignore (`false`) [strict types](https://ajv.js.org/strict-mode.html#strict-types) restrictions (the default is to log) |\n| `--strict-required=`| throw on (`true`) or log (`log`) [required properties](https://ajv.js.org/strict-mode.html#defined-required-properties) restrictions (the default is to ignore) |\n| `--allow-matching-properties`| allow `properties` [matching patterns](https://ajv.js.org/strict-mode.html#overlap-between-properties-and-patternproperties-keywords) in `patternProperties` |\n| `--allow-union-types`| allow [union types](https://ajv.js.org/strict-mode.html#union-types) |\n| `--validate-formats=false`| disable format validation |\n| Validation and reporting |\n| `--data`| use [$data references](https://ajv.js.org/guide/combining-schemas.html#data-reference) |\n| `--all-errors`| collect all validation errors |\n| `--verbose` | include schema and data in errors |\n| `--comment` | log schema `$comment`s |\n| `--inline-refs=` | referenced schemas compilation mode (true/false/\\\u003cnumber\\\u003e) |\n| Modify validated data |\n| `--remove-additional` | remove additional properties (true/all/failing) |\n| `--use-defaults` | replace missing properties/items with the values from default keyword |\n| `--coerce-types` | change type of data to match type keyword |\n| Advanced |\n| `--multiple-of-precision` | precision of multipleOf, pass integer number |\n| `--messages=false` | do not include text messages in errors |\n| `--loop-required=` | max size of `required` to compile to expression (rather than to loop) |\n| `--loop-enum=` | max size of `enum` to compile to expression (rather than to loop) |\n| `--own-properties` | only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) |\n| Code generation |\n| `--code-es5` | generate ES5 code |\n| `--code-lines` | generate multi-line code |\n| `--code-optimize=` | disable optimization (`false`) or number of optimization passes (1 pass by default) |\n| `--code-formats=` | code to require formats object (only needed if you generate standalone code and do not use [ajv-formats](https://github.com/ajv-validator/ajv-formats)) |\n\nOptions can be passed using either dash-case or camelCase.\n\nSee [Ajv Options](https://ajv.js.org/options.html) for more information.\n\n## Version History\n\nSee https://github.com/ajv-validator/ajv-cli/releases\n\n## Licence\n\n[MIT](./LICENSE)\n","funding_links":["https://github.com/sponsors/epoberezkin","https://opencollective.com/ajv"],"categories":["command-line"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajv-validator%2Fajv-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajv-validator%2Fajv-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajv-validator%2Fajv-cli/lists"}