Bartosz Bierkowski - Low dose cloud

OpenShift Morsels: displaying more information using json path

Day #11. There are several ways to display information about OpenShift objects. Today a post about the JSON path.

Lets start with a quick example. It iterates over items in pods list and displays pod names.

Kubernetes adds two new operations range/end and “”. First one can be used to iterate over elements like {range <array>}…{end}. Second one can be used to quote some text if you would like to display tab or newline characters (or anything else).

This allows us to format the displayed information into columns and import them easily. The example above displays pod name and the image names from containers inside pod. It would be better to again use a nested range here and take care of scenario when pod has multiple containers inside.

Honestly just could not make this scenario work. And it is not the first time I tried it.

If you need anything more complex than the examples above, use a programming language, where you can directly access json. Not sure if the implementation is not complete, or buggy here. There are few cases like filtering by label key/value, or more complex expressions, where using JSON path escapes my intuition. Still good to try it out by yourself. I find the idea of having a query language built into the command line tool very appealing.

The structure that you can navigate using the json path is whatever you get from oc get -o yaml <resource> . As you can see in the examples, just the output type used in -o  parameter is different.


The commands were executed using minishift and the following client/server versions of OpenShift.

oc v3.6.1+008f2d5
client kubernetes v1.6.1+5115d708d7
openshift v3.6.0+c4dd4cf
server kubernetes v1.6.1+5115d708d7


Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.

As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.

Did you like the article?
Join the newsletter to receive notifications about new articles.
I respect your privacy.