英文:
jq exclude key for output
问题
{
"I need to exclude field _class from this output:": "我需要从这个输出中排除字段_class:",
"What I use for get this json": "我用什么来获取这个JSON",
"Result must be just:": "结果应该只是:",
"I tried using |not and del, but that didn't work for me.": "我尝试使用|not和del,但对我没有起作用。"
}
英文:
I need to exclude field _class
from this output:
{
"_class": "hudson.model.FreeStyleBuild",
"displayName": "NAME-(#1498)",
"number": 1498
}
What I use for get this json
curl -gn http://<jenkins-site>/job/<build-name>/api/json?tree=builds[displayName,number]&pretty=true | jq -r '.builds[] | select(.displayName | contains("NAME"))'
Result must be just:
{
"displayName": "NAME-(#1498)",
"number": 1498
}
I tried using |not
and del
, but that didn't work for me.
答案1
得分: 3
你可以使用 del
命令来简单地删除该字段:
… | jq '.builds[] | select(.displayName | contains("NAME")) | del(._class)'
{
"displayName": "NAME-(#1498)",
"number": 1498
}
注意:如果输出为 JSON 格式,-r
标志不起作用。
英文:
You can simply delete that field using del
:
… | jq '.builds[] | select(.displayName | contains("NAME")) | del(._class)'
{
"displayName": "NAME-(#1498)",
"number": 1498
}
Note: If you output JSON, the -r
flag isn't doing anything.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论