How to extract Kubernestes PODS mac addresses from annotations object How to extract Kubernestes PODS mac addresses from annotations object kubernetes kubernetes

How to extract Kubernestes PODS mac addresses from annotations object


Starting with the original JSON and using jq's -r command-line option, the following jq filter yields the output shown below:

.[]| .metadata.annotations[]| (fromjson? // empty)| .[]| select(has("mac"))| {mac}

Output:

{"mac":"0a:2d:40:c6:f8:ea"}{"mac":"0a:52:8a:62:5d:f4"}{"mac":"0a:2d:40:c6:f8:ea"}{"mac":"0a:52:8a:62:5d:f4"}


Please try the below command and should get the expected output.

cat abc.json | jq -r  '.metadata.annotations."k8s.v1.cni.cncf.io/networks-status" | fromjson | .[].mac ' 

where abc.json is your son file.