v8r
A command-line JSON and YAML validator that's on your wavelength.
Getting Started
One-off:
npx v8r <filename>
Local install:
npm install -g v8r
v8r <filename>
Usage Examples
$ v8r package.json
Validating package.json against schema from https://json.schemastore.org/package ...
Errors:
[
{
keyword: 'type',
dataPath: '.name',
schemaPath: '#/properties/name/type',
params: { type: 'string' },
message: 'should be string'
}
]
❌ package.json is invalid
$ v8r action.yml
Validating action.yml against schema from https://json.schemastore.org/github-action ...
✅ action.yml is valid
$ v8r feature.geojson
❌ Could not find a schema to validate feature.geojson
$ v8r feature.geojson -s https://json.schemastore.org/geojson
Validating feature.geojson against schema from https://json.schemastore.org/geojson ...
✅ feature.geojson is valid
$ cat > my-catalog.json <<EOF
{ "\$schema": "https://json.schemastore.org/schema-catalog.json",
"version": 1,
"schemas": [ { "name": "geojson",
"description": "geojson",
"url": "https://json.schemastore.org/geojson.json",
"fileMatch": ["*.geojson"] } ] }
EOF
$ v8r feature.geojson -c my-catalog.json
ℹ️ Found schema in my-catalog.json ...
Validating feature.geojson against schema from https://json.schemastore.org/geojson ...
✅ feature.geojson is valid
Exit codes
-
v8r always exits with code 0
when:
- The input file was validated against a schema and the input file was valid
v8r
was called with --help
or --version
flags
-
By default v8r exits with code 1
when an error was encountered trying to validate the input file. For example:
- No suitable schema could be found
- An error was encountered during an HTTP request
- The input file did not exist
- The input file was not JSON or yaml
- etc
This behaviour can be modified using the --ignore-errors
flag. When invoked with --ignore-errors
v8r will exit with code 0
even if one of these errors was encountered while attempting validation. A non-zero exit code will only be issued if validation could be completed successfully and the file was invalid.
-
v8r always exits with code 99
when:
- The input file was validated against a schema and the input file was invalid
FAQ
❓ How does v8r
decide what schema to validate against if I don't supply one?
💡 v8r
queries the Schema Store catalog to try and find a suitable schema based on the name of the input file.
❓ My file is valid, but it doesn't validate against one of the suggested schemas.
💡 v8r
is a fairly thin layer of glue between Schema Store (where the schemas come from) and ajv (the validation engine). It is likely that this kind of problem is either an issue with the schema or validation engine.
❓ What JSON schema versions are supported?
💡 v8r
works with JSON schema drafts:
- draft-04
- draft-06
- draft-07
- draft 2019-09
- draft 2020-12
❓ Will 100% of the schemas on schemastore.org work with this tool?
💡 No. There are some with known issues
❓ Can v8r
validate against a local schema?
💡 Yes. The --schema
flag can be either a path to a local file or a URL.