Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    jdevillard
    @jdevillard
    items[?state.name=='WA'].status[].city[?contains(name,'Sea')].name[] give you the array with the result
    [
    "Seattle"
    ]
    xiemFortinet
    @xiemFortinet
    Cool, that's what I am looking for
    but I am not quite understand why do we need [] after status
    jdevillard
    @jdevillard
    It seems that you get an array of array
    Using [] you project and get only one array of object on which you can set the filter
    xiemFortinet
    @xiemFortinet
    Gotcha, thanks
    Trying to extract "Seattle" from the String "location/Seattle", does anyone has any thoughts about it?
    hell-racer
    @hell-racer
    jmespath doesn't have split out of the box
    xiemFortinet
    @xiemFortinet
    gotcha, thanks @hell-racer
    ِ
    @iboandyou_twitter
    im new to json can someone help me i have an ig messages.json and i only wanna filter the sender and the text
    hell-racer
    @hell-racer
    Hi! Please read https://jmespath.org/tutorial.html. If your data is not very complicated you'll probably find out how to do your query. If after that you'll still have problems, post you data, we'll try to help.
    Spencer Bliven
    @sbliven
    I'm interested in using jmespath strings to assign new values to an object. Is there any support for that?
    For instance, assign('name.first', 'spencer', {}) == {'name': {'first': 'Spencer'}}
    The syntax gets tricky once you want to start appending to arrays, but maybe it's possible
    I'm currently thinking I will have to parse the AST but then process it myself.
    Any tips here?
    hell-racer
    @hell-racer
    Hi! I'd try to use merge(), e.g. merge original object with another object with a single ptoperty.
    image.png
    jtrutwin
    @jtrutwin

    Hi, I think this is a FAQ but not seeing the answer, looking at the tutorial example for filtering:

    {
    "machines": [
    {"name": "a", "state": "running"},
    {"name": "b", "state": "stopped"},
    {"name": "b", "state": "running"}
    ]
    }

    machines[?state=='running'].name

    Is there a way to do this without checking case? match returns for Running, RUNNING, running, ruNNing etc

    hell-racer
    @hell-racer
    Hi! I don't think so. I suppose it always compares case sensitive.
    jtrutwin
    @jtrutwin
    yeah I haven't found much other than a couple requests to add custom functions to implement it - I ended up finding a different way to do this.
    lelejill
    @lelejill

    Hi, newbie here, I have a Json string want to transform from
    {
    "user": [
    {
    "birthday": "1990-01-01",
    "firstName": "Rob",
    "city": "Dublin"
    },
    {
    "birthday": "1989-01-01",
    "firstName": "Kevin",
    "city": "Tokyo"
    }
    ]
    }
    to

    [
    [Rob : Dublin : birthday : 1990-01-01],
    [Kevin : Tokyo : birthday : 1989-01-01]
    ]
    is there a good way to do it?

    hell-racer
    @hell-racer
    Hi!
    What you are posting as an expected result is not a valid json
    strings inside the array should be quoted and separated by commas
    hell-racer
    @hell-racer
    You can try this: user | [*] [firstName, city, birthday], and see if it's what you expect
    lelejill
    @lelejill
    Thanks @hell-racer, sorry, I didn't explain clearly, the expected result is more of string array instead of json
    hell-racer
    @hell-racer
    So is this result good enough?
    [
      [
        "Rob",
        "Dublin",
        "1990-01-01"
      ],
      [
        "Kevin",
        "Tokyo",
        "1989-01-01"
      ]
    ]
    lelejill
    @lelejill
    I need a colon between firstName, city and birthday, and a hardcoded birthday string (and colon) before it's value
    hell-racer
    @hell-racer
    I think it could be done, but... Jmes is all about json transformation, not random text transformation :)
    So it's easier to do this using a script or something
    lelejill
    @lelejill
    gotcha, yeah, the platform I am using can only use jmes without script capability
    can I add hardcoded string within the json
    hell-racer
    @hell-racer
    yes, just use single quotes
    hell-racer
    @hell-racer
    join('', ['[', join(', ', map(&join('', ['[', join(' : ', [firstName, city, 'birthday', birthday]), ']']), user|[*])), ']'])
    "[[Rob : Dublin : birthday : 1990-01-01], [Kevin : Tokyo : birthday : 1989-01-01]]"
    lelejill
    @lelejill
    👍, thanks @hell-racer
    Purushotham Reddy
    @purushothamkdr453
    Hi All, is it possible to substract the lists in jmespath or in general can we use arithmetic operators in jmespath if so can someone provdie me an example?
    hell-racer
    @hell-racer
    Hi!
    No math ops, sorry :)
    And what do you mean by subtracting lists?
    Sonia Gurdian
    @PendragonDay

    How does the && operator work? I cannot figure it out.
    This is my json:

    ``` {
    "Dev1": [
        "27035",
        "33602",
        "56087",
        "50022",
        "98825",
        "06693"
    ],
    "QA1": [
        "88204",
        "10359"
    ],
    "QA2": [
        "65784",
        "67235"
    ]

    }```
    I want to get something like this:

    QA1[] "&&" QA2[] to get both of the Q1 account numbers. But it is not working

    hell-racer
    @hell-racer
    Hi!
    Can you post expected result? I don't quite understand whether you want to concatenate strings, arrays or create a boolean expression.
    hell-racer
    @hell-racer
    I'm guessing you want to concatenate arrays, so maybe you need something like [QA1, QA2][]
    [
      "88204",
      "10359",
      "65784",
      "67235"
    ]
    Sonia Gurdian
    @PendragonDay
    @hell-racer I want to concatenate scaler QA1 and QA2 to return results from both. Your expected results is what I want. I will give it a try. Thank you.
    Sonia Gurdian
    @PendragonDay
    To add more details to my issue above. I'm using this expression with CloudCustodian https://pypi.org/project/c7n/ as a condition to evaluate a policy. But c7n is not expecting to find a list in the expression, given that this is concatenated with a , I get an error:unhashable type: 'list'... I will open an issue with them and go from there.
    glenveegee
    @glenveegee
    join(' ',[QA1, QA2][])