Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Brian Cunningham
    @kSeudo_twitter

    Hi, I am wondering if I can come up with a JMESpath query that counts instances of key pair values in an array.
    So an array like this:
    [
    { name : 'brian'},{ name: 'paul'},{ name: 'mary'}, { name: 'paul'}
    ]

    Would result in an object like this:
    {
    brian: 1,
    paul: 2,
    mary: 1
    ]

    Can anyone advise me if/how this transformation can be done in JMESpath?

    Thanks.

    Steffen Mandrup
    @steffenmanden_twitter

    Hi, was wondering if anyone knows if its possible to go into multiple nested arrays and grab values from all during the way ? in my case i got a colors[].sizes[] and i would like to get some values from colors before getting the values from sizes.

    My purpose is to make multiple objects based on each combination of those arrays - is it possible with jmespath directly ?

    Steffen Mandrup
    @steffenmanden_twitter
    Although i can see not all get responses in here :P
    Steffen Mandrup
    @steffenmanden_twitter
    I guess its related to all the parent talk though :D the big pain for me is that i could've solved it had it not been two level nested arrays as you could do a simple store/fetch function for 1 level, but if you can
    't access the mid level, then you're screwed :)
    Steffen Mandrup
    @steffenmanden_twitter
    Guess an ugly solution would be to do a function to combine elements in a first conversion and then run another conversion using what is desired
    Tomáš Mládek
    @tmladek
    Hi, I've got an object with a key which can be an empty string: {"foo": {"": {"bar": {"baz": 123}}} - and it seems it's getting handled weirdly by wildcards, say: foo."".bar.* returns [123] as expected, but foo.*.bar.* doesn't . This is weird, because foo.*.bar does return [{'baz': 123}], so it seems it's only the two wildcards together that produce this problem - am I doing something wrong?
    (using the python version if it makes a difference)
    James Haggerty
    @wryun
    @tmladek looks like a bug to me.
    @steffenmanden_twitter it's not entirely clear what you mean. Easier to see if you give an example input/output.
    Tomáš Mládek
    @tmladek
    @wryun will file this in issues then
    litakgit
    @litakgit

    Hi, I am new to jmespath.
    I see, there is no support if the key has space. For example : {"foo with space": "bar"} not parsable.

    jmespath.search("foo with space", {"foo with space" : bar}) --- doesn't work because having space in key is not supported.
    This is a small change like following to make it work -

    • VALID_IDENTIFIER = set(string.asciiletters + string.digits + '')
    • VALID_IDENTIFIER = set(string.asciiletters + string.digits + '' + ' ')

    Can we have it?

    Shashank Mehra
    @shashankmehra
    Try:
    jmespath.search("\"foo with space\"", {"foo with space" : bar})
    Basically if you have a path like x.foo.y, with space you will need to do x."foo with space".y
    x.`foo with space`.y would also probably work.
    litakgit
    @litakgit
    Thanks @shashankmehra !
    Chris Armstrong
    @chris-armstrong

    Is the jmespath.js variant looking for a maintainer? I noticed that no commits have been made for a few years, and there are outstanding pull requests / issues awaiting some input (including my own).

    I'm starting to use jmespath in my project, and I have some bandwidth to at least modernize it and deal with basic maintenance.

    At the moment I'm maintaining a private fork but would prefer not to
    Kaustubh Vinzanekar
    @kaustubh87
    Hi I have a json payload which has escape characters how do I make use of jmespath for payload which has escape ("\") characters in it? Is there an example which I can look for?
    Martijn Pieters
    @mjpieters
    @kaustubh87 : those \" elements are just quote characters. Just use the same syntax in your jmespath string literals?
    Because quote characters can't be part of an unquoted identifier (foo), you need to put quotes around such values anyway, so "foo\"bar", which is a JSON string with the value foo"bar.
    See the examples in the Identifiers section of the spec: http://jmespath.org/specification.html#examples
    Draiis
    @Emsys
    Hi guys
    i have question image a json with this structure : {
    "X": {
    "instance": [
    {
    "id": "1",
    "groupId": "1"
    },
    {
    "id": "2",
    "groupId": "2"
    },
    {
    "id": "3",
    "groupId": "2"
    }
    ]
    },
    "Y": {
    "group": [
    {
    "isSecure": true,
    "name": "group1",
    "groupId": "1"
    },
    {
    "isSecure": false,
    "name": "group2",
    "groupId": "2"
    },
    {
    "isSecure": false,
    "name": "group1",
    "groupId": "3"
    }
    ]
    }
    }
    Draiis
    @Emsys
    i try to compare field between different path Node for example i would like to filter the instance is the attached groupId have isSecure too true so a filter on the group should be something like this : Y.group[?groupId=='1' && isSecure] now if want to filter and aggregate on instance level i guess something like this should work X.instance[?groupId==X.instance[?groupId==Y.group[?isSecure].groupId]]
    but i can't found the solution
    on jsonpath its possible to refer to another node dimension and compare the curent node @ with another path
    for example like this @.field==$.anotherpath...
    Draiis
    @Emsys
    jsonpath equivalent is $..instance[?(@.groupId IN $.Y.group[?(@.isSecure==true)].groupId)]
    bosskay972
    @bosskay972
    Is there variable in JMES Path ?
    bosskay972
    @bosskay972
    Is it possible to make a array filter like this: @[?(age == max_by(@,&age))] ? Because with max by it return only one value and I want all value with the max value
    rmartin
    @rmartin-carecloud

    Hi all, I am tying to run a join within a conductor workflow using Jmespath, but can't seem to get the syntax right. Any help would be appreciated.

    Here is what I currently have.

    join(create_slots.output.response.body.data.createSlots[].json.resourceType $glue create_slots.output.response.body.data.createSlots[].json.id @)``

    rmartin
    @rmartin-carecloud

    Was able to figure it out.

    response.body.data.createSlots[].json.join('/', [resourceType, id])

    In case anyone is wondering.

    Michael Crawford
    @michael-crawford
    Hi all, new to this forum. I'm trying to extract some data from the aws ec2 describe-security-groups output, looking for ingress rules which have a description that starts with a value, and joining two 3 fields from one level with 2 fields in a nested array together via :, so I can iterate over the result creating a statement to delete matching rules. I thought I had painstakingly worked out every part, but when combined, I'm getting an error I can't figure out.
    Here's a version which returns the data I want unjoined:
    prefix=Temp
    username=MCrawford
    aws ec2 describe-security-groups --group-id $sg \
    --query 'SecurityGroups[].IpPermissions[?not_null(IpRanges[?Description!=null]|[?starts_with(Description, '$prefix-$username') == true])].[IpProtocol,FromPort,ToPort,IpRanges[?Description!=null]|[?starts_with(Description, '$prefix-$username') == true].[CidrIp,Description]]' \
    --profile $profile --region $region --output text
    udp 1194 1194
    70.185.154.223/32 Temp-MCrawford (VPN-UDP)
    tcp 22 22
    70.185.154.223/32 Temp-MCrawford (SSH)
    what I want is
    udp:1194:1194:70.185.154.223/32:Temp-MCrawford (VPN-UDP)
    tcp:22:22:70.185.154.223/32:Temp-MCrawford (SSH)

    What I thought would work is:
    aws ec2 describe-security-groups --group-id $sg \
    --query 'SecurityGroups[].IpPermissions[?not_null(IpRanges[?Description!=null]|[?starts_with(Description, '$prefix-$username') == true])].[join(:,[IpProtocol,to_string(FromPort),to_string(ToPort),IpRanges[?Description!=null]|[?starts_with(Description, '$prefix-$username') == true].join(:,[CidrIp,Description])])]' \
    --profile $profile --region $region --output text
    but this seems to have a problem with the second join, and is returning:
    In function join(), invalid type for value: ['70.185.154.223/32:Temp-MCrawford (VPN-UDP)'], expected one of: ['array-string'], received: "list"

    Can anyone spot my error? First time I'm really digging into this syntax in a serious way...

    Michael Crawford
    @michael-crawford
    Finally found it. The second filter was returning an array of 1 element, so I added a |[0] to convert to a string. This works:
    aws ec2 describe-security-groups --group-id $sg \
    --query 'SecurityGroups[].IpPermissions[?not_null(IpRanges[?Description!=null]|[?starts_with(Description, '$prefix-$username') == true])].[join(:,[IpProtocol,to_string(FromPort),to_string(ToPort),IpRanges[?Description!=null]|[?starts_with(Description, '$prefix-$username') == true]|[0].join(:,[CidrIp,Description])])]' \
    --profile $profile --region $region --output text
    Sorry to bother, maybe someone will find this useful. I'd still like to know if it's possible to simplify how the first filter works, where instead of filtering the IpPermissions there, I could accept all, then at the end, filter out IpPermissions which had an empty IpRanges array within them.
    Doqnach
    @Doqnach
    it would be easier if there was example input :-P
    Michael Crawford
    @michael-crawford
    Good point. I opened this: https://stackoverflow.com/questions/57070679/how-to-join-fields-from-one-array-level-with-fields-from-a-nested-array-level-wh, which goes into more detail in a formatted way. That shows the output prior to attempting the join in json format I was trying to join.
    russ
    @russau
    Is it possible to use the jmespath python library to modify a dictionary at the location of the jmespath query? i.e. like a jmespath "poke"?
    adam kaminski
    @thimslugga
    I'm trying to filter using aws cli and the --query option to only return resources which have multiple tags that match. I've got it working with 1 tag but checking if both tags (key and value) has proven more difficult
    anybody know how?
    aws efs describe-file-systems --query 'FileSystems[?Tags[?Key==Name]|[?Value==$name_tag]].FileSystemId'
    adam kaminski
    @thimslugga
    actually nvm, I figured it out :D
    Klaas Demter
    @Klaas-
    https://paste.fedoraproject.org/paste/RjTWwlEi2gFq1-e~6l3hXw can someone explain to me why the first query works but the 2nd query outputs []?
    bosskay972
    @bosskay972
    Is there upgrade on JMES Path in javascript ? Because I don't see any recent upgrade on the git. Is there planned upgrade or something ?
    Chris Armstrong
    @chris-armstrong
    @bosskay972 I'm maintaining a fork at @gorillastack/jmespath with some minor updates and fixes
    https://github.com/GorillaStack/jmespath.js/