Interview Prep/Shell Scripting/find, xargs, jq and yq

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq