1

I try to retrieve 1 in :

$ cat object.json 
{
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
        "annotations": {
            "deployment.kubernetes.io/revision": "1"
        }
    }
}
$ xidel -e '($json).metadata.annotations["deployment.kubernetes.io/revision"]' -s object.json 
{
  "deployment.kubernetes.io/revision": "1"
}

Tried

'($json).metadata.annotations."deployment.kubernetes.io/revision"'
'($json).metadata.annotations.("deployment.kubernetes.io/revision")'
'($json).metadata.annotations.(deployment.kubernetes.io/revision)'
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223

2 Answers2

1

I hardly ever use the dot-notation, because as far as I know in terms of capabilities it's rather limited.

JSONiq notation:

-e '$json("metadata")("annotations")("deployment.kubernetes.io/revision")'

Xpath-like notation with the XPath 3.1 map:get() function:

-e '$json/metadata/annotations/map:get(.,"deployment.kubernetes.io/revision")'

XPath 3.1 "?" lookup operator:

-e '$json?metadata?annotations?"deployment.kubernetes.io/revision"'

A combination of all notations:

-e '$json("metadata")/annotations?"deployment.kubernetes.io/revision"'
Reino
  • 3,203
  • 1
  • 13
  • 21
0

I've found:

$ xidel -e '($json).metadata.annotations(["deployment.kubernetes.io/revision"])' -s object.json
1

Is it a correct way to do it?

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223