JSONata - keys with dashes

I have some trouble selecting data from json, most key names contain dashes and jsonata does not seem to play along with it.

Example source (reality is much longer, many interfaces)

{
  "rpc-reply": {
    "$": {
      "xmlns:junos": "http://xml.juniper.net/junos/12.1X47/junos"
    },
    "interface-information": [
      {
        "$": {
          "xmlns": "http://xml.juniper.net/junos/12.1X47/junos-interface",
          "junos:style": "terse"
        },
        "physical-interface": [
          {
            "name": [
              "ge-0/0/0"
            ],
            "admin-status": [
              "up"
            ],
            "oper-status": [
              "up"
            ],
            "logical-interface": [
              {
                "name": [
                  "ge-0/0/0.0"
                ],
                "admin-status": [
                  "up"
                ],
                "oper-status": [
                  "up"
                ],
                "filter-information": [
                  "\n                "
                ]
              }
            ]
          },
          {
            "name": [
              "gr-0/0/0"
            ],
            "admin-status": [
              "up"
            ],
            "oper-status": [
              "up"
            ]
          },
          {
            "name": [
              "ip-0/0/0"
            ],
            "admin-status": [
              "up"
            ],
            "oper-status": [
              "up"
            ]
          }
        ]
      }
    ]
  }
}

I want to select from physical-interface, its admin-status where the literal name is ge-0/0/0.

Trying JSONata:

*["physical-interface"] // result - all
*["physical-interface"].name // no result
*["physical-interface"][name='ge-0/0/0'] // no result
*["physical-interface"]['name'='ge-0/0/0'] // no result
*["physical-interface"][name='ge-0/0/0'].['admin-status'] // no result
**.name // 2 results  

How does it work ? Does it work ? Or should i replace all keynames first ?

*["physical-interface"] Doesn't seem to be the correct syntax to select all interfaces, can you post an example with at leat 2 interfaces ?

hmm not sure what you mean, I have edited the post with more interfaces.

Ah, name is an array, this seems to works for me:
https://try.jsonata.org/0mypfEmj

Seems like keys with dashes need to be between backquotes:
**[name[0]="ge-0/0/0.0"].`admin-status`

Try **."physical-interface"[name[0]='ge-0/0/0']."admin-status"

this was tricky becase the name are all arrays - i.e. "name": ["ge-0/0/0"],

p.s. to test it, change the admin-status from 'up' to something else.

this was tricky becase the name are all arrays

Yes that confused me, because jsonata is used to select/search in arrays, except when trying to get this part.

@nlecaude thanks, this works!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.