I have a JSON array that looks like:
["a","b","c"]
And I have a bash variable which is list of array indices that I would like to subset to
ix="0,2"
I would like to use jq to subset to those indices, yielding the following array:
["a", "c"]
So far I've been able to parse $ix into an array:
echo '["a","b","c"]' | jq --arg ix $ix '$ix | split(",") | map(tonumber)'
But when I try to use this array of indices to subset ["a","b","c"], I have problems (None of the following work):
echo '["a","b","c"]' | jq --arg ix $ix '. | $ix | split(",") | map(tonumber)'
echo '["a","b","c"]' | jq --arg ix $ix '. | ($ix | split(",") | map(tonumber))'
echo '["a","b","c"]' | jq --arg ix $ix '. | [$ix | split(",") | map(tonumber)]'
echo '["a","b","c"]' | jq --arg ix $ix '. | .[$ix | split(",") | map(tonumber)]'