I would like to pass a nested key to jq in an arg. Using a single --arg key $mypath fails.
Looking at other questions it seems split is the correct method, but I cant find a basic example that works.
mypath="level1.level2.level3"
//working hardcode
jq '.level1.level2.level3' $myfile
//variations tried
jq --arg nest "${mypath}" '.[$nest]' $myfile
jq --arg nest "${mypath}" '.[$nest]|split(".")' $myfile
jq --arg nest "${mypath}" '.|split(".")|[$nest]' $myfile
>Solution :
You need getpath/1 for this. The method takes an array of paths to a particular node and returns the value present at it
jq --arg nest "$mypath" 'getpath($nest|split("."))'