jq Conditional output

JsonCommand LineJq

Json Problem Overview


I'm using jq to play with json. I was wondering how to conditionally print something in that.

Say I am interested in a field call geo. I used the following command and find out there is only one entry whose geo is null:

% cat all.json | jq '.geo != null' | sort | uniq -c              
   1 false
6891 true

How can I print out that entry only without printing everything else?

Didn't see something like print command in the manual. And this doesn't work: cat all.json | jq 'if .place == null then . end'. jq complained about syntax error.

Json Solutions


Solution 1 - Json

You can use the select function to get only required entries:

jq 'select(.geo != null)' all.json

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionclwenView Question on Stackoverflow
Solution 1 - Jsonmax taldykinView Answer on Stackoverflow