Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter empty and/or null values with jq

I have a file with jsonlines and would like to find empty values.

{"name": "Color TV", "price": "1200", "available": ""}
{"name": "DVD player", "price": "200", "color": null}

And would like to output empty and/or null values and their keys:

available: ""
color: null

I think it should be something like cat myexample | jq '. | select(. == "")', but is not working.

like image 492
Fernando César Avatar asked Sep 02 '25 02:09

Fernando César


1 Answers

Take a look at this snippet https://blog.nem.ec/code-snippets/jq-ignore-nulls/

jq -r '.firstName | select( . != null )' file.json
like image 76
Martín Coll Avatar answered Sep 05 '25 07:09

Martín Coll