我有以下JSON文档
[
{
"description": "Component 1",
"tags": [
"abc",
"123",
"xyz"
]
},
{
"description": "Component 2",
"tags": [
"def",
"foo",
"bar"
]
},
{
"description": "Component 3",
"tags": [
"def"
]
}
]
我在下面写了JQ过滤器来解析JSON,预期的输出不是生成多个字典。
{ (.[].description):(.[].tags)}
在应用滤波器后,由于tags
阵列,我使用multiple dictionaries
获得以下输出
{
"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生成上述预期输出?
您可以转换为这个
jq '.[] | { (.description) : .tags }'
为了消除多次出现的
演示