brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: paths() tells you where in a big JSON document a value lives

Json
~/tips/tip-json-paths-find-key

cat ~/tips/tip-json-paths-find-key.md

Find the exact route to a value without scrolling through nested output.

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

More Json tips echo '{"id":1,"payload":"{\"user\":\"ann\",\"tags\":[\"x\",\"y\"]}"}' | jq -c '.payload | fromjson | .tags' jq empty config.json jq -c --slurpfile u users.json ' jq -cn --stream 'fromstream(1|truncate_stream(inputs))' big.json const text = '{"createdAt":"2026-11-30T09:00:00Z","name":"x"}'; All Json tips (9) All topics

Link