want `json -s keylookup` to sort array output by given key
Useful for doing comparisons of two large JSON outputs.
If do this, the argument should be executable: i.e. a cmp function.
Also -o is taken.
Proposal:
... | json -s foo would sort on the "foo" key. A generalization would take multiple keys in order specified: ... | json -s foo -s bar.
Also have ... | json -S CODE where "CODE" is executable JS to run on each element of the array to generate a sorting key. Note that this "key" is different than a cmp function.
Y, me too: I am looking for a way to sort on date or a numeric field. Thx, M.
BTW, a hack, when wanting this came up again in a recent discussion: E.g. sort on 'time':
cat foo.log | json -ga time . -0 | sort | cut -c26-