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

Get all objects with attribute that does not have any of the provided substrings

$
0
0

Consider this basic JSON file:

{"list": [        {"random": 123,"fruits": "pineapple"        },        {"random": 42,"fruits": "peach"        },        {"random": 87,"fruits": "banana orange"        }    ]}

How do I get all objects in list that have a fruits attribute without the substrings "apple" and "nana" (for example)? The list of blacklisted substrings is variable, so hardcoding with and or or is not an option. I have tried this:

jq --argjson exl '["apple","nana"]''  .list[] | select(.fruits | any($exl[]; contains(.)) | not)'

It yields nothing, but I am expecting the object with "fruits": "peach". I feel like there is something wrong with my usage of any, but I can't find good documentation on it.


Viewing all articles
Browse latest Browse all 657

Trending Articles



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