jmespath

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": [ {

JmesPath find where not exists

你说的曾经没有我的故事 提交于 2019-12-02 03:51:24
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" } , {

Filter S3 list-objects results to find a key matching a pattern

流过昼夜 提交于 2019-11-30 06:43:21
I would like to use the AWS CLI to query the contents of a bucket and see if a particular file exists, but the bucket contains thousands of files. How can I filter the results to only show key names that match a pattern? For example: aws s3api list-objects --bucket myBucketName --query "Contents[?Key==*mySearchPattern*]" The --query argument uses JMESPath expressions. JMESPath has an internal function contains that allows you to search for a string pattern. This should give the desired results: aws s3api list-objects --bucket myBucketName --query "Contents[?contains(Key, `mySearchPattern`)]"

Filter S3 list-objects results to find a key matching a pattern

不打扰是莪最后的温柔 提交于 2019-11-29 06:17:25
问题 I would like to use the AWS CLI to query the contents of a bucket and see if a particular file exists, but the bucket contains thousands of files. How can I filter the results to only show key names that match a pattern? For example: aws s3api list-objects --bucket myBucketName --query "Contents[?Key==*mySearchPattern*]" 回答1: The --query argument uses JMESPath expressions. JMESPath has an internal function contains that allows you to search for a string pattern. This should give the desired

Filter output based on the existence of multiple key/value pairs

家住魔仙堡 提交于 2019-11-29 04:59:34
Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input? From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags - Environment / ABC Project / Project2 The closest I can get is to select a single matching Tag, but I require the rest of the object too, and I also need to match against the other key/value pair - Stacks[*].Tags[?Key=='Environment' && Value=='ABC'] Here is some exaple JSON input - { "Stacks": [ { "StackId": "abc123", "Tags": [ { "Value": "Project 1", "Key

Filter object by property and select with key in jmespath

本小妞迷上赌 提交于 2019-11-28 09:07:39
I'm trying to filter properties of an object in jmespath based on the value of a subproperty and want to include only those properties where the subproperty is set to a specific value. Based on this example data: { "a": { "feature": { "enabled": true, } }, "b": { }, "c": { "feature": { "enabled": false } } } I'd like to get an object with all properties where the feature is enabled. { "a": { "feature": { "enabled": true, } } } I figured I could use this jmespath query to filter the objects where property. enabled is set to true. Unfortunateley, it doesn't seem to work and instead returns an

Filter output based on the existence of multiple key/value pairs

╄→尐↘猪︶ㄣ 提交于 2019-11-27 18:55:06
问题 Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input? From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags - Environment / ABC Project / Project2 The closest I can get is to select a single matching Tag, but I require the rest of the object too, and I also need to match against the other key/value pair - Stacks[*].Tags[?Key=='Environment' && Value=='ABC'] Here

Xpath like query for nested python dictionaries

你。 提交于 2019-11-27 11:40:26
Is there a way to define a XPath type query for nested python dictionaries. Something like this: foo = { 'spam':'eggs', 'morefoo': { 'bar':'soap', 'morebar': {'bacon' : 'foobar'} } } print( foo.select("/morefoo/morebar") ) >> {'bacon' : 'foobar'} I also needed to select nested lists ;) This can be done easily with @jellybean's solution: def xpath_get(mydict, path): elem = mydict try: for x in path.strip("/").split("/"): try: x = int(x) elem = elem[x] except ValueError: elem = elem.get(x) except: pass return elem foo = { 'spam':'eggs', 'morefoo': [{ 'bar':'soap', 'morebar': { 'bacon' : { 'bla':

Xpath like query for nested python dictionaries

∥☆過路亽.° 提交于 2019-11-26 18:03:26
问题 Is there a way to define a XPath type query for nested python dictionaries. Something like this: foo = { 'spam':'eggs', 'morefoo': { 'bar':'soap', 'morebar': {'bacon' : 'foobar'} } } print( foo.select("/morefoo/morebar") ) >> {'bacon' : 'foobar'} I also needed to select nested lists ;) This can be done easily with @jellybean's solution: def xpath_get(mydict, path): elem = mydict try: for x in path.strip("/").split("/"): try: x = int(x) elem = elem[x] except ValueError: elem = elem.get(x)