Hello everyone, Is there a way to get an indented JSON output from `kubectl get . . .

Brtrnd Lprt:
hello everyone,
Is there a way to get an indented JSON output from kubectl get … -o jsonpath='' ?
The idea is to be able to build the jsonpath expression in a incremental way, like on the nice Kodekloud practice interface.
The flattened jsonpath output is unreadable

Mohamed Ayman:
Hi @Brtrnd Lprt,
this is and example to get an indented JSON output:
To get a singular Pod status, qualify your request with:
kubectl get pod $the_pod_name_here --output="jsonpath={.status}"

Brtrnd Lprt:
hello @Mohamed Ayman,
Thank you for your answer, but it doesn’t help much. JSON output from your command is flatened, like any other -o jsonpath output. This prevent from building jsonpath expression incrementally, with trial and error.

For example, in the Kodekloud interface https://kodekloud.com/courses/json-path-quiz/lectures/11339172 , you get a nice indented JSON as output on top right, which allows you to incrementally build jsonpath expressions, like :

.status .status.containerStatuses[1]
.status.containerStatuses[?(@.name == ‘redis-container’)] .status.containerStatuses[?(@.name == ‘redis-container’)].restartCount

I’m looking for a way to get nice human-readable indented JSON output from -o jsonpath commands, not flattened data.

Brtrnd Lprt:
managed to get something installing jq in the practice test. For example, for practice test 14.248.03 i was able to walk into JSON tree this way :

kubectl get node -o json|jq -r ‘.items[].status.nodeInfo.osImage’

To obtain :

kubectl get node -o jsonpath=‘{.items[*].status.nodeInfo.osImage}’

Too bad jq and jsonpath have slightly different syntaxes

Brtrnd Lprt:
A friend of mine showed me how to do it : just pipe jsonpath output to ‘jq .’
kubectl get … -o jsonpath=… | jq .
Is jq installed in the exam environnement ? Can we install it ?