Reputation: 40624
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
?
Upvotes: 1
Views: 2369
Reputation: 330
jq 'select(.requested_reviewers | length > 0)'
https://jqplay.org/s/Cw-nbWwmjz
Upvotes: 3