Remove objects from an array with jq


This took me a while.

So I had a JSON file with an array containing multiple objects, and I wanted to remove all that did not have a specific key. The internet was not so generous this time, as I found a lot of half solutions (to which I cannot point right now).

Eventually, I found two ways of doing this… so be my guest, future me:

I hope it will be useful for other people using jq too… stay safe!

Comments? Octodon, Twitter, GitHub, Reddit, or drop me a line!