<p>The JSON output returned to me after running this command </p>

<pre><code>kubectl get pods -o json | jq '.items[].spec.containers[].env'
</code></pre>

<p>on my kuberntes cluster is this</p>

<pre><code>[
  {
    "name": "USER_NAME",
    "value": "USER_NAME_VALUE_A"
  },
  {
    "name": "USER_ADDRESS",
    "value": "USER_ADDRESS_VALUE_A"
  }
]
[
  {
    "name": "USER_NAME",
    "value": "USER_NAME_VALUE_B"
  },
  {
    "name": "USER_ADDRESS",
    "value": "USER_ADDRESS_VALUE_B"
  }
]
</code></pre>

<p>I'd like to create a unified array/dictionary (Using <strong>Bash</strong> script) which looks like the example below and how can I get the value of each key?</p>

<pre><code>[
  {
    "USER_NAME": "USER_NAME_VALUE_A",
    "USER_ADDRESS": "USER_ADDRESS_VALUE_A"
  },
  {
    "USER_NAME": "USER_NAME_VALUE_B",
    "USER_ADDRESS": "USER_ADDRESS_VALUE_B"
  }
]
</code></pre>

James
<p>use the jsonpath</p>

<pre><code>C02W84XMHTD5:~ iahmad$ kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}'
coredns-c4cffd6dc-nsd2k
etcd-minikube
kube-addon-manager-minikube
kube-apiserver-minikube
kube-controller-manager-minikube
kube-dns-86f4d74b45-d5njm
kube-proxy-pg89s
kube-scheduler-minikube
kubernetes-dashboard-6f4cfc5d87-b7n7v
storage-provisioner
tiller-deploy-778f674bf5-vt4mj
</code></pre>

<p><a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/kubectl/jsonpath/</a></p>

<p>it can output key values as well</p>

<pre><code>C02W84XMHTD5:~ iahmad$ kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
coredns-c4cffd6dc-nsd2k 2018-10-16T21:44:19Z
etcd-minikube   2018-10-29T17:30:56Z
kube-addon-manager-minikube 2018-10-29T17:30:56Z
kube-apiserver-minikube 2018-10-29T17:30:56Z
kube-controller-manager-minikube    2018-10-29T17:30:56Z
kube-dns-86f4d74b45-d5njm   2018-10-16T21:44:16Z
kube-proxy-pg89s    2018-10-29T17:32:05Z
kube-scheduler-minikube 2018-10-29T17:30:56Z
kubernetes-dashboard-6f4cfc5d87-b7n7v   2018-10-16T21:44:19Z
storage-provisioner 2018-10-16T21:44:19Z
tiller-deploy-778f674bf5-vt4mj  2018-11-01T13:45:23Z
</code></pre>

<p>then you can split those by space and form json or list</p>
