Yq: Add support for built-in function 'sort, sort_by(path_expression)'

Created on 27 Sep 2017  路  2Comments  路  Source: mikefarah/yq

Add support for built-in function 'sort, sort_by(path_expression)'

The sort functions sorts its input, which must be an array. Values are sorted in the following order:

null
false
true
numbers
strings, in alphabetical order (by unicode codepoint value)
arrays, in lexical order
objects
The ordering for objects is a little complex: first they鈥檙e compared by comparing their sets of keys (as arrays in sorted order), and if their keys are equal then the values are compared key by key.

sort may be used to sort by a particular field of an object, or by applying any jq filter.

sort_by(foo) compares two elements by comparing the result of foo on each element.
enhancement from-jq

Most helpful comment

Unfortunately, using jq will remove comments. Can we re-open this issue ?

All 2 comments

Here is a workaround

~
yq r --tojson input.yaml | jq . | yq r -
~

Unfortunately, using jq will remove comments. Can we re-open this issue ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pcrocker-pivotal picture pcrocker-pivotal  路  3Comments

tadayosi picture tadayosi  路  6Comments

rgm3 picture rgm3  路  7Comments

mdubinko picture mdubinko  路  8Comments

tamalsaha picture tamalsaha  路  5Comments