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.
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