如何使用jq

时间:2019-01-09 13:07:08

标签: arrays json jq flatten

像json一样

[
  {
    "parent": "x",
    "children": ["a", "b"]
  },
  {
    "parent": "y",
    "children": ["c", "d", "e"]
  }
]

如何使用jq将其转换为“ [parent,child_order_number,child]”项数组,例如

[
  ["x", 0, "a"],
  ["x", 1, "b"],
  ["y", 0, "c"],
  ["y", 1, "d"],
  ["y", 2, "e"]
]

1 个答案:

答案 0 :(得分:1)

console.log('Type of test:', typeof test);

产量:

jq -c '[.[] | range(.children|length) as $i | [.parent, $i, .children[$i]]]' file