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

How do you convert between YAML and JSON in a script?

BeginnerConceptfind, xargs, jq and yq
Answer
yq -o=json '.' values.yaml > values.json        # YAML -> JSON (mikefarah yq v4)
yq -P '.' config.json > config.yaml             # JSON -> pretty YAML
kubectl get deploy api -o json | jq '.spec' | yq -P

JSON is valid YAML 1.2, so many tools accept it directly. Converting to JSON lets you reuse jq filters you already have.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq