Large API answers and inspect dumps nest things six levels deep. I know the value I am looking for and have no idea which keys lead to it.
Take this file, saved as stack.json:
{"services":{"web":{"image":"nginx","ports":[8080]},"db":{"image":"postgres"}}}
Ask where a value sits:
jq -c 'paths(. == "postgres")' stack.json
jq -c 'paths(. == 8080)' stack.json
The answers are ["services","db","image"] and ["services","web","ports",0]. Numbers in the path are array positions. To get something you can read at a glance, join the parts with dots:
jq -r 'paths(. == "nginx") | join(".")' stack.json
That prints services.web.image.
The match is exact, including the type, so 8080 and "8080" are different things. One thing to watch: a key that contains dots will make the joined version ambiguous. Use the array form when you plan to feed the path back into getpath. I also run it on a file I have never seen before, searching for a hostname or an id I recognise, just to learn how the thing is laid out.
Further reading: jq manual