# JSONata - keys with dashes

**URL:** <https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943>\
**Category:** General\
**Created:** [18 February 2020 19:42 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943 "2020-02-18T19:42:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 February 2020 19:42 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/1 "2020-02-18T19:42:59Z")

</div>

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)

```auto
{
  "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:

```auto
*["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 ?

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [18 February 2020 20:00 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/2 "2020-02-18T20:00:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 February 2020 20:02 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/3 "2020-02-18T20:02:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [18 February 2020 20:48 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/4 "2020-02-18T20:48:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [18 February 2020 20:51 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/5 "2020-02-18T20:51:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 February 2020 22:18 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/6 "2020-02-18T22:18:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 February 2020 23:10 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/7 "2020-02-18T23:10:57Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 March 2020 23:11 UTC](https://discourse.nodered.org/t/jsonata-keys-with-dashes/21943/8 "2020-03-03T23:11:02Z")

</div>

Closed on 3 March 2020 23:11 UTC

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