3 ms·
only if you're sure that .count is never null: $ echo '[{"a": {"count": null}}]' | jq -c 'sort_by(-.count)' jq: error (at <stdin>:1): null (null) cannot be
by philsnow 3y ago
only if you're sure that .count is never null:
$ echo '[{"a": {"count": null}}]' | jq -c 'sort_by(-.count)'
jq: error (at <stdin>:1): null (null) cannot be negated
$ echo '[{"a": {"count": null}}]' | jq -c 'sort_by(.count) | reverse'
[{"a":{"count":null}}]
- mdaniel 3y agothis whole thread is like nerd sniping me :-D but I felt compelled to draw attention to jq's coalesce operator because I only recently learned about it and searching for the word "coalesce" in the man page is pfffft (it's official name is "Alternative operator", with alternative being "for false and null") $ echo '[{"a": {"count": null}}]' | jq -c 'sort_by(-(.count//0))' [{"a":{"count":null}}]