如何使用 jq 将 json 项目值映射到兄弟数组
How to map json item value to sibling array with jq
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"]
]
?
jq -c '[.[] | range(.children|length) as $i | [.parent, $i, .children[$i]]]' file
产量:
[["x",0,"a"],["x",1,"b"],["y",0,"c"],["y",1,"d"],["y",2,"e"]]
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"]
]
?
jq -c '[.[] | range(.children|length) as $i | [.parent, $i, .children[$i]]]' file
产量:
[["x",0,"a"],["x",1,"b"],["y",0,"c"],["y",1,"d"],["y",2,"e"]]