-
-
Notifications
You must be signed in to change notification settings - Fork 23
yaml validate
William W. Kimball, Jr., MBA, MSIS edited this page Oct 18, 2020
·
3 revisions
The yaml-validate
command-line tool validates one or more single- or multi-document YAML, JSON, and compatible files. Under its default configuration, the following output is generated:
- When there are no issues:
$ yaml-validate valid*.*
$ echo $?
0
- When there are validation errors:
$ yaml-validate invalid*.*
invalid-multidoc.json/1 is invalid due to:
* YAML parsing error in "invalid-multidoc.json", line 3, column 1: expected ',' or ']', but got '['
invalid-multidoc.yaml/1 is invalid due to:
* YAML composition error in "invalid-multidoc.yaml", line 10, column 19: found undefined alias 'alias'
invalid-singledoc.json/0 is invalid due to:
* YAML parsing error in "invalid-singledoc.json", line 1, column 3: expected the node content, but found '}'
invalid-singledoc.yaml/0 is invalid due to:
* YAML syntax error in "invalid-singledoc.yaml", line 3, column 12: mapping values are not allowed here
$ echo $?
2
For this demonstration, there were 4 deliberately invalid documents; YAML and JSON single- and multi-document files. Each of the multi-document files contained 3 documents with a deliberate error on the second of each type.
When you want the report to also list valid documents, add the --verbose
flag, like so:
$ yaml-validate --verbose valid*.*
valid-multidoc.json/0 is valid.
valid-multidoc.json/1 is valid.
valid-multidoc.json/2 is valid.
valid-multidoc.yaml/0 is valid.
valid-multidoc.yaml/1 is valid.
valid-multidoc.yaml/2 is valid.
valid-singledoc.json/0 is valid.
valid-singledoc.yaml/0 is valid.
$ echo $?
0
A verbose report against all 8 valid and invalid documents would be much more noisy:
$ yaml-validate --verbose *.*
invalid-multidoc.json/0 is valid.
invalid-multidoc.json/1 is invalid due to:
* YAML parsing error in "invalid-multidoc.json", line 3, column 1: expected ',' or ']', but got '['
invalid-multidoc.yaml/0 is valid.
invalid-multidoc.yaml/1 is invalid due to:
* YAML composition error in "invalid-multidoc.yaml", line 10, column 19: found undefined alias 'alias'
invalid-singledoc.json/0 is invalid due to:
* YAML parsing error in "invalid-singledoc.json", line 1, column 3: expected the node content, but found '}'
invalid-singledoc.yaml/0 is invalid due to:
* YAML syntax error in "invalid-singledoc.yaml", line 3, column 12: mapping values are not allowed here
valid-multidoc.json/0 is valid.
valid-multidoc.json/1 is valid.
valid-multidoc.json/2 is valid.
valid-multidoc.yaml/0 is valid.
valid-multidoc.yaml/1 is valid.
valid-multidoc.yaml/2 is valid.
valid-singledoc.json/0 is valid.
valid-singledoc.yaml/0 is valid.
$ echo $?
2
When the --help
(-h
) flag is passed to yaml-validate
, it generate the following documentation:
usage: yaml-validate [-h] [-V] [-S] [-d | -v | -q] [YAML_FILE [YAML_FILE ...]]
Validate YAML, JSON, and compatible files.
positional arguments:
YAML_FILE one or more single- or multi-document YAML/JSON/compatible
files to validate; omit or use - to read from STDIN
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-S, --nostdin Do not implicitly read from STDIN, even when there are no -
pseudo-files in YAML_FILEs with a non-TTY session
-d, --debug output debugging details
-v, --verbose increase output verbosity (show valid documents)
-q, --quiet suppress all output except system errors
Except when suppressing all report output with --quiet|-q, validation issues
are printed to STDOUT (not STDERR). Further, the exit-state will report 0 when
there are no issues, 1 when there is an issue with the supplied command-line
arguments, or 2 when validation has failed for any document.