<p>I'm following <a href="https://www.katacoda.com/courses/kubernetes/liveness-readiness-healthchecks" rel="nofollow noreferrer">https://www.katacoda.com/courses/kubernetes/liveness-readiness-healthchecks</a></p>

<p>I saw an interesting command to parse json object use flag <code>-o=jsonpath</code> in kubectl as below: </p>

<pre><code># pod=$(kubectl get pods --selector="name=bad-frontend" --output=jsonpath={.items..metadata.name})

# kubectl describe pod $pod
</code></pre>

<p>How <code>map[string]interface {}, []interface {}{map[string]interface {}, map[string]interface {}{}</code> is used in the raw json?</p>

<p>How can I easily know <code>{.itme..metadata.name}</code> is correct, not using something <code>{..item.metadata..name}</code>?</p>

<p>Raw file to check (if you pass wrongly {}, it will return this to you):</p>

<pre><code>map[string]interface {}{"kind":"List", "apiVersion":"v1", "metadata":map[string]interface {}{}, "items":[]interface {}{map[string]interface {}{"status":map[string]interface {}{"phase":"Running", "conditions":[]interface {}{map[string]interface {}{"type":"Ready", "status":"False", "lastProbeTime":interface {}(nil), "lastTransitionTime":"2018-01-03T14:41:26Z", "reason":"ContainersNotReady", "message":"containers with unready status: [bad-frontend]"}}, "hostIP":"127.0.0.1", "podIP":"172.18.0.3", "startTime":"2018-01-03T14:41:26Z", "containerStatuses":[]interface {}{map[string]interface {}{"ready":false, "restartCount":6, "image":"katacoda/docker-http-server:unhealthy", "imageID":"docker://sha256:dc680e51481ae0256b5483e0d3c0bd188215a67b0926d4ed07e8a9fe55e16154", "containerID":"docker://3a067a667e8e73784c761d75c3614d3aa138a6d498b22b48e1c23aa1d8158170", "name":"bad-frontend", "state":map[string]interface {}{"waiting":map[string]interface {}{"reason":"CrashLoopBackOff", "message":"Back-off 2m40s restarting failed container=bad-frontend pod=bad-frontend-zbgrw_default(28bdddce-f094-11e7-9f7b-0242ac110036)"}}, "lastState":map[string]interface {}{"terminated":map[string]interface {}{"containerID":"docker://3a067a667e8e73784c761d75c3614d3aa138a6d498b22b48e1c23aa1d8158170", "exitCode":2, "reason":"Error", "startedAt":"2018-01-03T14:44:57Z", "finishedAt":"2018-01-03T14:45:06Z"}}}}}, "kind":"Pod", "apiVersion":"v1", "metadata":map[string]interface {}{"name":"bad-frontend-zbgrw", "generateName":"bad-frontend-", "uid":"28bdddce-f094-11e7-9f7b-0242ac110036", "labels":map[string]interface {}{"name":"bad-frontend"}, "annotations":map[string]interface {}{"kubernetes.io/created-by":"{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"default\",\"name\":\"bad-frontend\",\"uid\":\"24a58c4a-f094-11e7-9f7b-0242ac110036\",\"apiVersion\":\"v1\",\"resourceVersion\":\"15\"}}\n"}, "namespace":"default", "selfLink":"/api/v1/namespaces/default/pods/bad-frontend-zbgrw", "resourceVersion":"300", "creationTimestamp":"2018-01-03T14:41:18Z"}, "spec":map[string]interface {}{"restartPolicy":"Always", "terminationGracePeriodSeconds":30, "dnsPolicy":"ClusterFirst", "nodeName":"127.0.0.1", "securityContext":map[string]interface {}{}, "containers":[]interface {}{map[string]interface {}{"terminationMessagePath":"/dev/termination-log", "imagePullPolicy":"IfNotPresent", "name":"bad-frontend", "image":"katacoda/docker-http-server:unhealthy", "resources":map[string]interface {}{}, "livenessProbe":map[string]interface{}{"timeoutSeconds":1, "periodSeconds":10, "successThreshold":1, "failureThreshold":3, "httpGet":map[string]interface {}{"path":"/", "port":80, "scheme":"HTTP"}, "initialDelaySeconds":1}, "readinessProbe":map[string]interface {}{"httpGet":map[string]interface {}{"path":"/", "port":80, "scheme":"HTTP"}, "initialDelaySeconds":1, "timeoutSeconds":1, "periodSeconds":10, "successThreshold":1, "failureThreshold":3}}}}}}}
</code></pre>

<p>I'm happy that I found a good solution explained in details here:
<a href="https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba" rel="nofollow noreferrer">https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba</a></p>

<p>Basically you have to install jq or jiq, then type <code>kubectl get no -o json | jid -q | pbcopy</code>.
The fun part begins: you type . and item, etc will be proposed for you to choose, you can easily construct your filter syntax.</p>
