https://github.com/romnn/gojsonschema-cli
Golang CLI to validate JSON or YAML files against a JSON schema
https://github.com/romnn/gojsonschema-cli
ajv go golang jsonschema validate
Last synced: about 1 month ago
JSON representation
Golang CLI to validate JSON or YAML files against a JSON schema
- Host: GitHub
- URL: https://github.com/romnn/gojsonschema-cli
- Owner: romnn
- License: apache-2.0
- Created: 2024-10-20T00:13:28.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-01-07T20:02:08.000Z (9 months ago)
- Last Synced: 2025-07-04T14:25:47.663Z (3 months ago)
- Topics: ajv, go, golang, jsonschema, validate
- Language: Go
- Homepage: https://json-schema.org
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON schema validation CLI


[](https://goreportcard.com/report/github.com/romnn/gojsonschema-cli)A golang CLI wrapper for [xeipuuv/gojsonschema](https://github.com/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.
```bash
brew install romnn/tap/jsonschema# or from source:
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.```bash
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
```bash
jsonschema validate -s ./schemas/my-schema.json -v ./my-data.json
```Also, you can validate against remote schemas:
```bash
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:
```bash
jsonschema validate -s ./values.schema.json -v ./values.prod.yaml
```## Development
To use the provided tasks in `taskfile.yaml`, install [task](https://taskfile.dev/).
```bash
# 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:
```bash
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](https://github.com/xeipuuv/gojsonschema) under the hood.
- This CLI intentionally behaves very similar to the internal JSON schema validation of [`helm lint`](https://github.com/helm/helm/blob/main/pkg/chartutil/jsonschema.go).
- This CLI has a similar goal as [neilpa/yajsv](https://github.com/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](https://github.com/xeipuuv/gojsonschema).