How do you validate JSON and YAML files in a CI step?
IntermediateConceptfind, xargs, jq and yq
Answer
for f in config/*.json; do jq empty "$f" || { echo "invalid JSON: $f" >&2; exit 1; }; done
for f in k8s/*.yaml; do yq 'true' "$f" >/dev/null || { echo "invalid YAML: $f" >&2; exit 1; }; done
yamllint -s k8s/ # style plus syntax, strict mode
kubeconform -strict k8s/ # validate against Kubernetes schemas
jq empty parses and prints nothing, failing with a parse error message on bad input.
More on find, xargs, jq and yq
What are the most useful `find` predicates for operations work?BeginnerWhat is the difference between `-exec cmd {} \;`, `-exec cmd {} +` and `-delete`?IntermediateHow does `find` evaluate `-o` (OR) and why do you need parentheses?AdvancedWhat does `xargs` do, and which flags matter?IntermediateWhy is `find | xargs rm` dangerous and what is the safe form?IntermediateWhat is `jq` and what are the filters you use every day?Beginner