JSON schema validation CLI

A golang CLI wrapper for xeipuuv/gojsonschema.
Features:
- Simple to install (static go binary)
- Validate JSON or YAML files against a JSON schema
- Check JSON schemas for correctness
- Supports local and remote schemas
Note: Only schemas up to draft07
are officially supported.
go install 'github.com/romnn/gojsonschema-cli/cmd/jsonschema@main'
Validate a JSON schema
This is similar to ajv's compile
, in that we validate the JSON schema itself.
This can be useful when you first want to ensure that your schemas are well-formed.
jsonschema validate -s ./schemas/my-schema.json
# assuming my-schema.json uses draft 07, this would be equal:
jsonschema validate -s "http://json-schema.org/draft-07/schema#" -v ./schemas/my-schema.json
Validate a file against a schema
jsonschema validate -s ./schemas/my-schema.json -v ./my-data.json
Also, you can validate against remote schemas:
export REMOTE="https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone-strict"
jsonschema validate -s "${REMOTE}/horizontalpodautoscaler.json" -v ./my-autoscaler.json
Also, you can validate YAML files, such as helm values files:
jsonschema validate -s ./values.schema.json -v ./values.prod.yaml
Development
To use the provided tasks in taskfile.yaml
, install task.
# view all available tasks
task --list-all
# install development tools (requires brew/linuxbrew)
task dev:tools:install
After setup, you can use the following tasks during development:
task tidy
task run:race
task run:race -- validate -s ./schema.json -v ./values.json
task build:race
task test
task lint
task format
Acknowledgements
- This CLI uses xeipuuv/gojsonschema under the hood.
- This CLI intentionally behaves very similar to the internal JSON schema validation of
helm lint
.
- This CLI has a similar goal as neilpa/yajsv, which does not support remote schemas, schema checking, and other features.
License
The project is licensed under the same license as xeipuuv/gojsonschema.