Quantcast
Viewing all articles
Browse latest Browse all 526

jq - return array value if its length is not null

I have a report.json generated by a gitlab pipeline.It looks like:

{"version":"14.0.4","vulnerabilities":[{"id":"64e69d1185ecc48a1943141dcb6dbd628548e725f7cef70d57403c412321aaa0","category":"secret_detection"....and so on

If no vulnerabilities found, then "vulnerabilities":[]. I'm trying to come up with a bash script that would check if vulnerabilities length is null or not. If not, print the value of the vulnerabilities key. Sadly, I'm very far from scripting genius, so it's been a struggle.While searching web for a solution to this, I've come across jq. It seems like select() should do the job.I've tried:

jq "select(.vulnerabilities!= null)" report.json

but it returned {"version":"14.0.4","vulnerabilities":[{"id":"64e69d1185ecc48a194314... instead of expected "vulnerabilities":[{"id":"64e69d1185ecc48a194314...and

map(select(.vulnerabilities != null)) report.json

returns "No matches found"

Would you mind pointing out what's wrong apart from my 0 experience with bash and JSON parsing?


Viewing all articles
Browse latest Browse all 526

Trending Articles