Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Alex Domoradov
    @alexeyd-itsoft
    @chris-armstrong thx a lot for you help, I have a little bit modified your solution and got the following
    nodes.*.services[] | @[?contains(node_id, 'master')]  | @[?contains(service_id,'srv1')].service_id | @[0]
    now I get service id for specific service name
    zeus357
    @zeus357
    Hi all, is it possible to map the value of an element in the jmespath expression? for example, using the below data, if version=='1', then set version output as 'A'. similarly, if version=='2', then set version output as 'B'...etc. Any help would be appreciated.
    [
    {
    "type": "book",
    "title": "spiderman",
    "version": "1"
    },
    {
    "type": "dvd",
    "title": "spiderman",
    "version": "2"
    }
    ]
    Chris Armstrong
    @chris-armstrong
    From what I can see, the language wouldn't permit you to do this - there is map function and merge function, but you're not able to express index lookups using a variable, only a number literal.
    This is as close as I got, but this won't compile
    map(&merge(@, (`[{"version": "A"}, {"version": "B"}]`)[@.version]), @)
    zeus357
    @zeus357
    Thanks Chris
    anotherPassword
    @anotherPassword
    Any thoughts on this issue I am having? Query "instance.availableField[?startswith(name, 'ansible')]" Works in JMESPath tutorial but throws error in ansible tower:
    "msg": "JMESPathError in json_query filter plugin:\nIn function starts_with(), invalid type for value: LastBackupStatus-com.dellemc.avamar, expected one of: ['string'], received: \"unknown\"",
    "_ansible_no_log": false
    data looks like this:
      instance:
        availableField:
        - managedObjectType: vim.VirtualMachine
          _vimtype: vim.CustomFieldsManager.FieldDef
          key: 402
          fieldInstancePrivileges: 
          fieldDefPrivileges: 
          type: str
          name: 'LastBackupStatus-com.dellemc.avamar'
    I tried quotes on name: value same thing
    anotherPassword
    @anotherPassword
    Fixed it with "{{ msg | to_json | from_json | json_query(query) }}", is the correct way to address this or is thera fix?
    Ryan Merolle
    @ryanmerolle
    hello all. I have a question about grouping keys in a nested dictionary
    [ 
       { 
          "name":1,
          "endpoints":[ 
             { 
                "switch":"switch-1",
                "ip":"192.168.1.1/30"
             },
             { 
                "switch":"switch-2",
                "ip":"192.168.1.2/30"
             }
          ]
       },
       { 
          "name":2,
          "endpoints":[ 
             { 
                "switch":"switch-1",
                "ip":"10.0.0.1/30"
             },
             { 
                "switch":"switch-3",
                "ip":"10.0.0.2/30"
             }
          ]
       }
    ]
    I want to loop to create a list similar to [["192.168.1.1/30" , "192.168.1.2/30" ],["10.0.0.1/30" , "10.0.0.2/30" ]]
    I am able to get list of all ips under endpoints as 1 list using [].endpoints[].ip
    but I want in this case, 2 lists (or however many dictionaries that I find in the above list)
    thanks as always
    nevermind!
    [].endpoints.[*].ip does the trick...answered my own question
    Doqnach
    @Doqnach
    @ryanmerolle [].endpoints[*].ip gets you in the right direction
    ow you fixed it already :-P
    Ryan Merolle
    @ryanmerolle
    thanks @Doqnach
    Doqnach
    @Doqnach
    think you have a . too much
    Ryan Merolle
    @ryanmerolle
    yea that was a typo on chat
    Mitch Schooler
    @MitchSchooler_twitter
    Hi, I'm trying to use jmespath within a Tavern API test executed by pytest and I don't seem to be able to use the search() function. Other jmespath functions are working fine but for some reason I keep getting "jmespath.exceptions.UnknownFunctionError: Unknown function: search()" when trying to use the search function. Any idea why this one would not be found when other jmespath functionality is working as expected?
    I'm trying to do something like:
              function: tavern.testutils.helpers:validate_content
              extra_kwargs:
                comparisons:
                  - jmespath: "search(members, @)"
    Chris Armstrong
    @chris-armstrong
    jmespath itself doesn't have a search() function - this is typically the API name for calling JMESPath with an object and expression.
    You probably just want a filter expression i.e. array[?some_property == 'value1']
    Mitch Schooler
    @MitchSchooler_twitter
    Okay, thanks for that clarification. I'm sure I'm just missing something super obvious here, but I thought search() was how you accessed the value of a particular key in a map. What is the proper way to do this? For example, how do I get "bar" out of this map the way that this search() example shows without search()?
    search(foo, {"foo": "bar"}) -> "bar"
    Chris Armstrong
    @chris-armstrong
    bar - literally just the property name
    Mitch Schooler
    @MitchSchooler_twitter
    In my case I only know the expected key (foo) and its value could vary. How do I get the value out of the map using the foo key?
    Chris Armstrong
    @chris-armstrong
    sorry I meant foo
    Mitch Schooler
    @MitchSchooler_twitter
    Oh, so like: @[foo] ?
    Chris Armstrong
    @chris-armstrong
    no just foo or @.foo
    Mitch Schooler
    @MitchSchooler_twitter
    Gotcha, I'll give that a try. Thanks!
    Chris Armstrong
    @chris-armstrong
    @[foo] gives you ['bar']
    Mitch Schooler
    @MitchSchooler_twitter
    I see. So how would I get "ids" from this nested example? Would it just be @.members.ids and it should give me back ["id1", "id2"] ?
    {
        "members": {
            "ids": [
                "id1",
                "id2"
            ]
        }
    }
    Chris Armstrong
    @chris-armstrong
    yep
    sinusx
    @sinusx_gitlab
    Hi! Week ago I have found online tool where I can make query by jmespath language, now I can not find it again. Please provide link if you know?
    jdevillard
    @jdevillard
    Hello you’ve different tool available
    The site jmespath.org with de javascript impl
    sinusx
    @sinusx_gitlab
    @jdevillard Thank you!!!
    broskees
    @broskees
    Hey guys!
    Discovered JMESpath a few days ago