Quick snippets to help with extracting data elements from a JSON object.
Given these keys in persistent configuration database, snippets below extract various bits of data.
{
"network:interfaces:physical:ixgbe0:netmask": "255.255.255.0",
"network:interfaces:physical:e1000g1:create": true,
"network:interfaces:physical:igb0:tag": [
"admin",
"primary"
],
"network:interfaces:physical:e1000g2:broadcast": null,
"network:interfaces:physical:ixgbe0:broadcast": null,
"network:interfaces:physical:e1000g1:netmask": "255.255.255.0",
"network:interfaces:physical:e1000g1:tag": [
"ipmp"
],
"network:interfaces:physical:ixgbe1:tag": [
"aggr",
"service",
"10gb"
],
"network:interfaces:physical:ixgbe0:tag": [
"aggr",
"service",
"10gb"
],
"network:interfaces:physical:e1000g2:tag": [
"ipmp"
],
"network:interfaces:physical:ixgbe1:create": false,
"network:interfaces:physical:ixgbe1:netmask": null,
"network:interfaces:physical:e1000g1:group": "ip0",
"network:interfaces:physical:ixgbe0:address": null,
"network:interfaces:physical:e1000g2:address": null,
"network:interfaces:physical:e1000g1:address": null,
"network:interfaces:physical:e1000g0:create": true,
"network:interfaces:physical:e1000g1:failover": false,
"network:interfaces:physical:e1000g2:failover": false,
"network:interfaces:physical:ixgbe1:mtu": 9000,
"network:interfaces:physical:ixgbe1:gateway": null,
"network:interfaces:physical:ixgbe0:create": false,
"network:interfaces:physical:e1000g2:create": true,
"network:interfaces:physical:e1000g0:tag": [
"normal"
],
"network:interfaces:physical:e1000g0:mtu": 1500,
"network:interfaces:physical:e1000g1:broadcast": null,
"network:interfaces:physical:igb0:gateway": null,
"network:interfaces:physical:e1000g1:mtu": 1500,
"network:interfaces:physical:igb0:create": true,
"network:interfaces:physical:e1000g0:gateway": null,
"network:interfaces:physical:ixgbe1:broadcast": null,
"network:interfaces:physical:e1000g0:broadcast": null,
"network:interfaces:physical:igb0:mtu": 1500,
"network:interfaces:physical:ixgbe1:address": null,
"network:interfaces:physical:igb0:netmask": null,
"network:interfaces:physical:igb0:address": "dhcp",
"network:interfaces:physical:ixgbe0:mtu": 9000,
"network:interfaces:physical:e1000g2:mtu": 1500,
"network:interfaces:physical:e1000g0:netmask": null,
"network:interfaces:physical:e1000g0:address": "dhcp",
"network:interfaces:physical:ixgbe1:aggr": "aggr1",
"network:interfaces:physical:e1000g1:gateway": null,
"network:interfaces:physical:igb0:broadcast": null,
"network:interfaces:physical:e1000g2:group": "ip0",
"network:interfaces:physical:e1000g2:gateway": null,
"network:interfaces:physical:ixgbe0:aggr": "aggr1",
"network:interfaces:physical:ixgbe0:gateway": null,
"network:interfaces:physical:e1000g2:netmask": "255.255.255.0"
}
# cat /tmp/d.json | jq -r 'keys[]'| awk 'FS=":" {print $4}'|sort -u
e1000g0
e1000g1
e1000g2
igb0
ixgbe0
ixgbe1
cat /tmp/d.json | jq -r ".[\"network:interfaces:physical:igb0:mtu\"]"
1500
cat /tmp/d.json | jq -r ".[\"network:interfaces:physical:e1000g2:create\"]"
true
cat /tmp/d.json | jq -r ".[\"network:interfaces:physical:igb0:tag\"][]"
admin
primary
cat /tmp/d.json | jq -r ".[\"network:interfaces:physical:ixgbe0:tag\"][]"
aggr
service
10gb
cat /tmp/d.json | jq -r ".[\"network:interfaces:physical:e1000g1:group\"]"
ip0
cat /tmp/d.json | jq -r ".[\"network:interfaces:physical:ixgbe0:aggr\"]"
aggr1