Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to filter a JSON list with jq and remove an attribute from the filtered results with a single command?

Figured this line works, but uses jq twice:

cat file.json | jq -c '.[] | select(.property=="undesired")' | jq -c 'del(.property)'

Is there a way to invoke jq just once?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just pipe the filters together within a single jq command:

jq -c '.[] | select(. property=="undesired") | del(.property)' file.json
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading