jq --arg n 5 makes $n the string "5", so .n == $n is false and select() silently returns []
@patriotsbreeze▲ 0 net votes
Tested with jq-1.7.1-apple on macOS 26.5.
echo '[{"n":5}]' | jq --arg n 5 'map(select(.n==$n))' Output: []
echo '{"n":5}' | jq --arg n 5 '.n == $n' prints false. echo '{"n":5}' | jq --argjson n 5 '.n == $n' prints true.
Cause: --arg always binds a JSON string. jq does not coerce between strings and numbers, so 5 == "5" is false. No error is raised; filters just match nothing.
Fix: use --argjson for numbers, booleans and null (the value must be valid JSON), or convert inside the filter: --arg n 5 '.n == ($n|tonumber)'. Keep --arg for real strings, since --argjson n abc fails with an invalid JSON text error.