# kubectl get -o jsonpath: Usage, Options & Common CI Errors

> kubectl get -o jsonpath extracts exact fields for scripting. Range syntax, quoting in CI shells, and the empty-output trap that breaks pipelines.

Source: https://latchkey.dev/learn/command-reference/kubectl-get-o-jsonpath  
Updated: 2026-06-25

Pull one exact field out of a resource for a script to consume.

kubectl get -o jsonpath=... extracts specific fields from a resource as plain text, the workhorse for scripting against the API in CI. Getting the syntax and quoting right is what keeps a pipeline robust.

## What it does

The jsonpath template addresses into the JSON object: {.status.phase} reads one field, {.items[*].metadata.name} maps over a list, and {range .items[*]}...{end} iterates with custom separators. Wrap the whole template in single quotes so the shell does not expand the braces and dots.

## Common usage

```Terminal
kubectl get pod my-pod -o jsonpath='{.status.podIP}'
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.cpu}{"\n"}{end}'
kubectl get deploy/web -o jsonpath='{.spec.template.spec.containers[*].image}'
```

## Common errors in CI

The pipeline-breaker is silent empty output: a wrong path or a field that does not exist yet prints nothing and exits 0, so a downstream variable becomes empty and a later step fails confusingly. Assert the result is non-empty (test -n) before using it. "error: error parsing jsonpath ... unexpected" usually means the shell ate the braces - single-quote the template. A leading dollar-brace like {.status} is fine, but unquoted in a CI YAML run block the shell may try to expand it; quote defensively. For booleans/numbers, jsonpath prints them as text, so compare as strings.

## Using this in CI

A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.

```Terminal
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods

# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info

# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes
```

> Always set `--request-timeout` in CI. Without it an unreachable API server hangs until the job times out, which turns a thirty-second failure into a twenty-minute one.

## FAQ

### kubectl get -o jsonpath: Usage, Options & Common CI Errors?

kubectl get -o jsonpath=... extracts specific fields from a resource as plain text, the workhorse for scripting against the API in CI. Getting the syntax and quoting right is what keeps a pipeline robust.

### What it does?

The jsonpath template addresses into the JSON object: {.status.phase} reads one field, {.items[*].metadata.name} maps over a list, and {range .items[*]}...{end} iterates with custom separators. Wrap the whole template in single quotes so the shell does not expand the braces and dots.

### Common errors in CI?

The pipeline-breaker is silent empty output: a wrong path or a field that does not exist yet prints nothing and exits 0, so a downstream variable becomes empty and a later step fails confusingly. Assert the result is non-empty (test -n) before using it. "error: error parsing jsonpath ...

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
