3
1
I have an array of JSON data being printed to the terminal (OS X) and I want the properties of that to be displayed in a table in the terminal.
Sample query:
aws ec2 describe-instances
| jq '[ .[] | .[] | .Instances[] as $ins
| { groups: $ins.SecurityGroups[].GroupName,
addresses: [ $ins.PrivateIpAddress, $ins.PublicIpAddress ],
dns: $ins.PrivateDnsName,
name: ($ins.Tags[] as $ts | $ts.Key == "Name" | $ts.Value ) }
| select(.name | contains("prod")) ]'
Stated another way: I want to take the resulting data structure (array of object that contains properties 'addresses', 'groups', 'dns', 'name') and shove each object into a line of a table, inside the terminal/bash.
I don't mind to let the data be EOF-ed before the table starts drawing.
Example JSON:
[
{
"name": "prod-clusterX-01",
"dns": "ip-10-34-XX-XX.eu-west-1.compute.internal",
"addresses": [
"10.34.XX.XX",
"54.246.XX.XX"
],
"groups": "prod-clusterX"
},
{
"name": "prod-revproxy-a",
"dns": "ip-10-0-XX-XX.eu-west-1.compute.internal",
"addresses": [
"10.0.XX.XX",
"54.229.XX.XX"
],
"groups": "prod-revproxy"
}
]
1can we see an example of the JSON? – simon – 2013-08-26T10:30:31.947
are you open to solutions that depend upon, e.g.
python
, or third-party tools (at minimumsed
,awk
etc.)? – simon – 2013-08-26T11:49:07.550