7

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.

4

3 回答 3

4

您可以这样使用map过滤器:

jq 'map(.[0])'
于 2013-09-19T09:16:40.113 回答
1

另一种选择是jq '[.[][0]]'

这给出了与使用相同的结果map(.[0])

于 2016-09-15T19:53:58.750 回答
0

这是使用reduce的解决方案

reduce .[] as $k ( null; . + [$k[0]] )
于 2017-08-02T07:18:22.113 回答