我有以下 JSON 檔案
[
{
"description": "Component 1",
"tags": [
"abc",
"123",
"xyz"
]
},
{
"description": "Component 2",
"tags": [
"def",
"foo",
"bar"
]
},
{
"description": "Component 3",
"tags": [
"def"
]
}
]
我在 JQ 過濾器下面寫了決議 JSON,預期的輸出不是生成多個字典。
{ (.[].description):(.[].tags)}
應用過濾器后,multiple dictionaries由于tags陣列,我得到以下輸出
{
"Component 1": [
"abc",
"123",
"xyz"
]
}
{
"Component 1": [
"def",
"foo",
"bar"
]
}
{
"Component 1": [
"def"
]
}
{
"Component 2": [
"abc",
"123",
"xyz"
]
}
{
"Component 2": [
"def",
"foo",
"bar"
]
}
{
"Component 2": [
"def"
]
}
{
"Component 3": [
"abc",
"123",
"xyz"
]
}
{
"Component 3": [
"def",
"foo",
"bar"
]
}
{
"Component 3": [
"def"
]
}
我期待的輸出沒有multiple dictionaries如下
{
"Component 1": [
"abc",
"123",
"xyz"
]
}
{
"Component 2": [
"def",
"foo",
"bar"
]
}
{
"Component 3": [
"def"
]
}
如何使用 JQ 生成上述預期的輸出?
uj5u.com熱心網友回復:
你可以轉換成這個
jq '.[] | { (.description) : .tags }'
為了擺脫多次出現
Demo
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/394290.html
