Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

how to group_by with tables' key name

$
0
0

My input json file:

{ "london": [ "x", 0 ] }{ "london": [ "y", 97 ] }{ "paris": [ "x", 15 ] }{ "paris": [ "y", 8 ] }

I try to group by key and make the output:

{ "london":  ["x", 0], ["y", 97] },{ "paris":   ["x", 15], ["y", 8] }

or:

{ "london": [ {"x", 0}, {"y", 97} ] },{ "paris":  [ {"x", 15}, {"y", 8} ] }

The following command give me an error message:

 jq -s 'group_by(keys_unsorted[0]) | map({(.[0]): map(.[1])})'

jq: error (at :4): Cannot index object with number

I try to change the numbers to strings, but, it does not help.I guess that I missed something in the map (?)


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>