Reputation: 3919
I want to have an output with static value using jq with static value :4546
nodes.json
{
"nodes": {
"node1.local": {
":ip": "10.0.0.1",
"ports": [],
":memory": 1024,
":bootstrap": "bootstrap.sh"
},
"node2.local": {
":ip": "10.0.0.2",
"ports": [],
":memory": 1024,
":bootstrap": "bootstrap.sh"
},
"node3.local": {
":ip": "10.0.0.3",
"ports": [],
":memory": 1024,
":bootstrap": "bootstrap.sh"
}
}
}
here is my command use
ips=`jq -c '.nodes | to_entries | map(.value.":ip")' nodes.json`
echo $ips
where the output is
["10.0.0.1", "10.0.0.2", "10.0.0.3"]
and i want it to be like this
["10.0.0.1:4546", "10.0.0.2:4546", "10.0.0.3:4546"]
Upvotes: 1
Views: 1456
Reputation: 6075
You could use map_values
jq -c '.nodes | to_entries | map(.value.":ip")| map_values(.+":4546")' nodes.jso
Upvotes: 0
Reputation: 10661
You can simply use + operator:
jq '.nodes | to_entries | map(.value.":ip" + ":4546")'
Upvotes: 0