jsonpath — the mental model Link to heading

The dot notation is just the YAML structure of the resource, flattened.

Whatever you see in k get <resource> -o yaml — that’s the map. Every key is a dot. Every list item is [0] or [*].

The thinking method Link to heading

Step 1 — run this:

k get <resource> <name> -o yaml

Step 2 — read the YAML, trace the path to what you want

Example — you want the token from a secret:

apiVersion: v1
data:
  token: abc123==
kind: Secret

Path: .data.token

Example — you want a pod’s first container image:

spec:
  containers:
  - name: nginx
    image: nginx:1.19

Path: .spec.containers[0].image

That’s the entire system. There’s no separate API to memorize. jsonpath IS the YAML, just with dots instead of indentation and [n] for list positions.

The only syntax to burn in Link to heading

situationsyntax
nested key.parent.child
list, first item[0]
list, all items[*]
secret data is always base64always pipe | base64 -d

On the exam Link to heading

If you blank on the path — run -o yaml first, read it, then write the jsonpath. Takes 10 seconds.

Full command pattern Link to heading

# get the value
k get <resource> <name> -o jsonpath='{.path.to.field}'

# get decoded secret value
k get secret <name> -n <ns> -o jsonpath='{.data.token}' | base64 -d

# write directly to file
k get secret <name> -n <ns> -o jsonpath='{.data.token}' | base64 -d > /opt/course/5/token