JmesPath find where not exists

我是研究僧i 提交于 2019-12-04 04:57:35

问题


The following JmesPath expression finds instances that have been tagged with a team:

"Instances[?Tags[?Key=='team']]"

Do you know how to find instances that are not tagged with a team?

I have tried:

"Instances[?!Tags[?Key=='team']]"
-> !Tags[?Key=='team']]: event not found
"Instances[?null==Tags[?Key=='team']]"
-> []  <-- wrong answer
"Instances[?!not_null(Tags[?Key=='team'])]"
-> !not_null: event not found

Many thanks in advance!

Sample input:

{ "Instances":
  [ { "id": "i-911"
    , "Tags":
      [ {"Key":"owner", "Value":"Edu"}
      , {"Key":"team", "Value":"forensics"}
      ]
    , "many other keys": "stuff"
    }
  , { "id": "i-999"
    , "Tags":
      [ {"Key":"owner", "Value":"Edu"}
      , {"Key":"note", "Value":"No team!"}
      ]
    , "many other keys": "stuff"
    }
  ]
}

回答1:


Solved: Parentheses are the answer:

"Instances[?!(Tags[?Key=='team'])]"


来源:https://stackoverflow.com/questions/42396971/jmespath-find-where-not-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!