The Sort Keys operator sorts maps by their keys (based on their string value). This operator does not do anything to arrays or scalars (so you can easily recursively apply it to all maps).
Sort is particularly useful for diffing two different yaml documents:
yq eval -i 'sortKeys(..)' file1.ymlyq eval -i 'sortKeys(..)' file2.ymldiff file1.yml file2.yml
Given a sample.yml file of:
c: froga: blahb: bing
then
yq eval 'sortKeys(.)' sample.yml
will output
a: blahb: bingc: frog
Note the array elements are left unsorted, but maps inside arrays are sorted
Given a sample.yml file of:
bParent:c: dogarray:- 3- 1- 2aParent:z: donkeyx:- c: yumb: delish- b: ewa: apple
then
yq eval 'sortKeys(..)' sample.yml
will output
aParent:x:- b: delishc: yum- a: appleb: ewz: donkeybParent:array:- 3- 1- 2c: dog