Simplesmente com a opção --argjson
, que considerará $cnt
variable como o valor JSON :
cnt=0
$ jq --argjson cnt "$cnt" '.data[$cnt]' file.json
A saída:
{
"id": 1,
"name": "John"
}
--argjson name JSON-text
:This option passes a JSON-encoded value to the jq program as a predefined variable. If you run jq with
--argjson foo 123
, then$foo
is available in the program and has the value123