jq getpath error: Cannot index number with string "id"
16:16 21 Apr 2026

What's wrong with:

jq '[paths | select(.[-1] == "id") | {"path": ., "value": getpath(.)}]' <(echo '[{ "id": 1, "child": { "id": 2 } }]')

I get following error:

jq: error (at /dev/fd/63:1): Cannot index number with string "id"

Expected output:

{"path": [0,"id"], "value": 1}, {"path": [1,"child","id"], "value": 2}]
json bash jq