How do I get jq to take json like this:
{
\"host1\": { \"ip\": \"10.1.2.3\" },
\"host2\": { \"ip\": \"10.1.2.2\" },
\"host3\": { \"ip\
Came across very elegant solution
jq 'with_entries(.value |= .ip)'
Which ouputs
{
"host1": "10.1.2.3",
"host2": "10.1.2.2",
"host3": "10.1.18.1"
}
Here is the jqplay snippet to play with: https://jqplay.org/s/Jb_fnBveMQ
The function with_entries converts each object in the list of objects to Key/Value-pair, thus we can access .key or .value respectively, we're updating (overwriting) every KV-item .value with the field .ip by using update |= operator