Basic jq usage. How to get nested value
Tho dot in `storage_server.disk_total" needs to be escaped to prevent it from being interpreted as an object key separator. so you can use:
jq '.stats."storage_server.disk_total"'
assuming that XXXXXXXXXX
is a valid JSON number in your real JSON.
To get deeply nested values by their key:
$ jq '.. |."storage_server.disk_total"? | select(. != null)'
..
is a shortcut for the zero-argument recurse
-- an analog of the XPath //
operator.
- For learning how to construct jq queries, it is more useful to look at the tutorial and manual than the "man" page. There's also a FAQ.
- The inner key name has a period in it, and therefore the
.keyname
shorthand cannot be used for it. So you could write:
.stats["storage_server.disk_total"]
or if your jq allows it:
.stats."storage_server.disk_total"
These are both abbreviations for:
.stats | .["storage_server.disk_total"]