jq - How to use jq to not show a json data if a field is an empty array?
问题描述
I have some github data in json format like so:
{
"id": 18535,
"node_id": "MDExhN0M8877883",
"number": 747,
"state": "closed",
"locked": false,
"title": "Generate cordova protos",
"user": {
"login": "Superhacker"
},
"body": "Simple PR",
"created_at": "2018-05-02T07:43:39Z",
"updated_at": "2018-07-21T02:09:14Z",
"closed_at": "2018-05-02T07:54:56Z",
"merge_commit_sha": "4bf92c0332c66999999b6c0a766e",
"assignee": null,
"assignees": [],
"requested_reviewers": [],
"requested_teams": [],
"labels": [],
"milestone": null,
"draft": false,
"author_association": "CONTRIBUTOR"
}
I want to NOT showing the json strings when the requested_reviewers
is empty.
I have tried several ways
echo <the json string above> | jq '.requested_reviewers | select(. != "")
It shows []
echo <the json string above> | jq '.requested_reviewers | select(! empty)
It gave a syntax error.
echo <the json string above> | jq '.requested_reviewers | select(. != empty)
Now jq
does not print out anything as I wanted.
But if I feed a json with non empty requested_reviewers
, it also does not print anything.
Besides I don't want to just print out the field. I want to be able to see the entire json string.
How can I achieve my goal with jq
?
解决方案
select(.requested_reviewers != [])
推荐阅读
- powershell - 带有 if 语句的 Powershell foreach 循环仅评估第一个语句
- spring-integration - Spring Integration 配置现有流程
- xamarin.android - 对象引用未设置为片段中的对象实例
- flutter - Flutter:在堆栈中的动画图像上触发 GestureDetector
- katalon-studio - 有谁知道在我进入 Katalon 的搜索字段后如何模拟单击键盘上的输入按钮
- python - 贝叶斯优化可能不适用于 CNN 的一些原因是什么
- java - 为什么我不能将非常规类型的 Arraylist<> 注册到 ArrayList<> 中?
- pdfsharp - pdfsharp 超链接 AddDocumentLink 在触摸屏 Android 上不起作用
- c - 在没有现有定义的情况下使用 typedef 是什么意思
- node.js - Node.js express console.log 不显示任何内容