jq print key and value for all in sub-object
Simply pipe to keys
function:
Sample input.json
:
{
"connections": {
"host1": { "ip": "10.1.2.3" },
"host2": { "ip": "10.1.2.2" },
"host3": { "ip": "10.1.18.1" }
}
}
jq -r '.connections | keys[] as $k | "\($k), \(.[$k] | .ip)"' input.json
The output:
host1, 10.1.2.3
host2, 10.1.2.2
host3, 10.1.18.1