I have a jq script that's transforming JSON data. I'd like to check if the value for a particular field belongs to a list of 'valid' values for the field and leave it unmodified if it does. For a browser field I have this for example:
if . == "chrome" or . == "edge" or . == "firefox" or . == "safari" or . == "opera" then .
This works but writing out each possible value in a "or . == this" like that feels very convoluted and messy. I'm wondering if there's a cleaner method that looks more like a pythonic:
if . in ["chrome", "edge", "firefox", "safari", "opera"] then .
What's the best way of checking membership in a list of values with jq?
EDIT: I believe this is different from the marked duplicate as the array isn't contained within the JSON data. I'd like to know how to take an element with a single value (e.g. a string) from the JSON data and check whether this element appears in an array provided as part of a conditional. The JSON data itself doesn't contain any arrays.