문제

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.

도움이 되었습니까?

해결책

You can use map filter this way:

jq 'map(.[0])'

다른 팁

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

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

Here is a solution using reduce

reduce .[] as $k ( null; . + [$k[0]] )
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top