【发布时间】:2018-03-07 03:54:31
【问题描述】:
我试图让 jq 从 json 文件中删除一个内部节点,json 文件如下所示:
{
"etag": "14b3796c268c87553291702c808e86dfe1e53d1b",
"rules": {
"name": "default",
"children": [
{
"name": "xxxx",
"children": [
{
"name": "dffaa42b-3f0f-425f-a9a1-a63cd35b2517",
"children": [],
"behaviors": [
{
"name": "xxx",
"options": {
"key": "xxx-xxx-xxx-xxx",
"compress": true,
"ports": ""
}
}
],
"criteria": [
{
"name": "xxxx",
"options": {
"Name": "UUID",
"values": [
"dffaa42b-3f0f-425f-a9a1-a63cd35b2517"
]
}
}
],
"criteriaMustSatisfy": "all"
},
{
"name": "7004389c-c47a-4611-9bd7-9f5dfe051d17",
"children": [],
"behaviors": [
{
"name": "xxx",
"options": {
"key": "xxx-xxx-xxx-xxx",
"compress": true,
"ports": ""
}
}
],
"criteria": [
{
"name": "xxxx",
"options": {
"Name": "UUID",
"values": [
"7004389c-c47a-4611-9bd7-9f5dfe051d17"
]
}
}
],
"criteriaMustSatisfy": "all"
}
],
"behaviors": [],
"criteria": [],
"criteriaMustSatisfy": "all"
}
],
"behaviors": [
{
"name": "xxx",
"options": {}
}
],
"options": {
"is_secure": true
},
"variables": []
},
"warnings": [
],
"Format": "xxx"
}
我可能混淆了json结构,但是我现在的jq查询如下:
(.rules.children[].children[] | select(.name | contains("7004389c-c47a-4611-9bd7-9f5dfe051d17")| not ))
这可行,但它返回的 json 不包括来自 .rules.children[].children[] 的子项。
我如何让 jq 返回整个 json 文件,不包括过滤器中识别的 json?
【问题讨论】:
-
我忘了提,我基本上想返回相同的 json,除了:{“name”:“7004389c-c47a-4611-9bd7-9f5dfe051d17”,“children”:[],“behaviors ": [ { "name": "xxxx", } ], }
-
您可以edit您的问题,而不是在cmets中添加信息。
-
@Dale,你的json无效,贴出实际的
-
@RomanPerekhrest 道歉,我已经修改以包含正确的 Json