Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 524

Using if-then-else-end in jq to handle missing values

$
0
0

This is the command I use to pull the info I need:

.results | .[] | {id, name: .general.name, platform: .general.platform, site: .general.site.name, ea_site: .extensionAttributes.[] | select(.definitionId=="57").values.[]}

When .extensionAttributes.[] | select(.definitionId=="57").values.[] is empty, jq does not display any associated items at all.

What I'd like to do is check if .extensionAttributes.[] | select(.definitionId=="57").values.[] < 0 and return empty otherwise return the content. I'm trying to use if-then-else-end, but can't seem to get the syntax correct.

You can find sample data in jqplay here.Line 1218 in the json input has the empty value.


Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>