for (( i=1; i<=groupCount; i++ )) ;
do
echo $i
echo $(echo "$input" | jq --arg i $i '.SecurityGroups[$i]')
done
This returns an error:
jq: error (at <stdin>:189): Cannot index array with string "1"
2
jq: error (at <stdin>:189): Cannot index array with string "2"
3
jq: error (at <stdin>:189): Cannot index array with string "3"
Is there any way around this?
I have the same scenario and am also wondering what a possible solution might be for this.
Either cast the argument to a number (as in .SecurityGroups[$i | tonumber]) or obtain the argument as a JSON value in the first place (as in --argjson i "$i")
Most helpful comment
Either cast the argument to a number (as in
.SecurityGroups[$i | tonumber]) or obtain the argument as a JSON value in the first place (as in--argjson i "$i")