kubernetes: JsonPath nested condition and multiple conditions are not working

I want to get the list of all pods that are ready to take requests. In order to do that I run the following queries:

kubectl get pods -l app=my-app -o jsonpath='{.items[?(@.status.conditions[?(@.type == "Ready")].status == "True")].status.phase}'

OR

kubectl get pods -l app=my-app -o jsonpath='{.items[?(@.status.conditions[*].type == "Ready" && @.status.conditions[*].status == "True")].status.phase}'

Neither of them works. Jsonpath doesn’t support nested filters or multiple filters.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 42
  • Comments: 35 (18 by maintainers)

Commits related to this issue

Most upvoted comments

So now that RFC9535: JSONPath: Query Expressions for JSON is a proposed standard by the IETF, perhaps it’s time to reopen this and expand the implementation?

Such functionality is super-useful for print columns, kubectl and potentially other areas in Kubernetes.

Is there current ongoing work to apply this new standard somewhere? If so, would be happy if someone can provide a pointer to the relevant KEP or similar document, thanks!

P.S. It might be worth considering using CEL instead of JSONPath; but in general, any solution providing more advanced querying capabilities would be useful to the community in my opinion.

👋 Is this being worked on anywhere? If not I could take a look.

/reopen Issue still there

Seems a new draft was release three days ago: https://datatracker.ietf.org/wg/jsonpath/documents/

Working to get the first part of the implementation merged over at #79227

Looks like there’s one in the process of being drafted: https://tools.ietf.org/html/draft-goessner-dispatch-jsonpath-00