Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select nth element from multidimensional JSON array with jq

How can I use jq to transform this array of arrays:

[
  [
    "sequence",
    "int"
  ],
  [
    "time",
    "string"
  ],
  ...
]

Into an array that contains the first (0) element from every subarray? Meaning to produce output like this:

[
    "sequence",
    "time",
    ...
]

I was thinking to use reduce xx as $item (...) but I didnt manage to come up with anything useful.

like image 355
Dreen Avatar asked Sep 16 '13 21:09

Dreen


2 Answers

You can use map filter this way:

jq 'map(.[0])'
like image 87
Psylone Avatar answered Oct 02 '22 04:10

Psylone


Another option would be jq '[.[][0]]'

this gives the same result as using map(.[0])

like image 23
rdm Avatar answered Oct 02 '22 04:10

rdm