jq --arg v alice '.[] | select(.name == $v)' data.json

Category: Data Science & Analysis

jq --arg v alice '.[] | select(.name == $v)' data.json

Filter JSON by a shell variable value

The --arg flag binds a shell string to a jq variable, here v holding alice, referenced as $v inside the filter. This keeps the filter free of hard-coded values so the same command works for any name. Variable values are always strings; use --argjson for numbers and booleans. This is the safe way to inject data into jq expressions.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.