How to check if element exists in array with jq

前端 未结 5 803
悲哀的现实
悲哀的现实 2020-12-08 14:53

I have an array and I need to check if elements exists in that array or to get that element from the array using jq, fruit.json:

{
    \"fr         


        
5条回答
  •  既然无缘
    2020-12-08 14:54

    For future visitors, if you happen to have the array in a variable and want to check the input against it, and you have jq 1.5 (without IN), your best option is index but with a second variable:

    .inputField as $inputValue | $storedArray|index($inputValue)

    This is functionally equivalent to .inputField | IN($storedArray[]).

提交回复
热议问题