Reputation: 3919
I want to have an output that instead of delimeter space it should be like this ", " using jq
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=`cat /vagrant/nodes.json | jq -r '.nodes | to_entries[] | [.value.":ip"] | @tsv'`
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", "10.0.0.2", "10.0.0.3"]
Upvotes: 0
Views: 91
Reputation: 212208
$ jq -c '.nodes | to_entries | map(.value.":ip")' input
["10.0.0.1","10.0.0.2","10.0.0.3"]
Upvotes: 1