json icon indicating copy to clipboard operation
json copied to clipboard

want `json -s keylookup` to sort array output by given key

Open trentm opened this issue 14 years ago • 4 comments

Useful for doing comparisons of two large JSON outputs.

trentm avatar Oct 11 '11 20:10 trentm

If do this, the argument should be executable: i.e. a cmp function.

Also -o is taken.

trentm avatar May 23 '12 05:05 trentm

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.

trentm avatar Aug 15 '12 17:08 trentm

Y, me too: I am looking for a way to sort on date or a numeric field. Thx, M.

mrjcleaver avatar Jan 15 '15 19:01 mrjcleaver

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-

trentm avatar Nov 04 '16 00:11 trentm