0

I am trying to apply the filter using JMESPath jp (https://github.com/jmespath/jp) utility. My goal is to have only the flow whose state is 'ADDED' and having specific device id (e.g. 0000debf17cff54b) filtered out.

I am trying something like this: cat test | ./jp '[][?id=="of:00002259146f7743" && state=="ADDED"]' but the result is []

[
  {
    "flow": [
      {
        "ethType": "0x86dd",
        "type": "ETH_TYPE"
      },
      {
        "protocol": 58,
        "type": "IP_PROTO"
      },
      {
        "icmpv6Type": 135,
        "type": "ICMPV6_TYPE"
      }
    ],
    "id": "of:00001aced404664b",
    "state": "ADDED"
  },
  {
    "flow": [
      {
        "ethType": "0x86dd",
        "type": "ETH_TYPE"
      },
      {
        "protocol": 58,
        "type": "IP_PROTO"
      },
      {
        "icmpv6Type": 136,
        "type": "ICMPV6_TYPE"
      }
    ],
    "id": "of:0000debf17cff54b",
    "state": "ADDED"
  }
]
MAQ
  • 673
  • 6
  • 11

1 Answers1

1

No need to use the first [], [?id=='of:0000debf17cff54b' && state=='ADDED'] works fine.

Using the first [] gives you the entire array, that does not contain a id or state keys.

nadavbrkt
  • 87
  • 5
  • yes, that is correct. However, the real culprit seems to be that you need to use single quotes for the strings. And then, double quote for the whole filter expression. – MAQ Jan 24 '18 at 16:14