Where communities thrive


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

    If you could... would you want to be able to do something like this:

    expect(
        search([6.1, 4.2, 6.3], "_groupBy(@, as_lambda('Math.floor'))")
    ).toStrictEqual({
          '4': [4.2],
          '6': [6.1, 6.3],
        });

    or perhaps

    expect(
        search([1, 2], "_flatMap(@, as_lambda('x => [x, x]'))")
    ).toStrictEqual([1, 1, 2, 2]);

    Thoughts?

    glenveegee
    @glenveegee
    Meh... did it anyway. _flatMap, _groupBy and 184 other (fully typed) functions have been built into JMESPath expressions in our https://www.npmjs.com/package/@metrichor/jmespath-plus library. Level-up your JMESPath expressions with the power of lodash functions. Check out https://github.com/nanoporetech/jmespath-plus/releases/tag/v0.3.0 for a complete list of supported lodash functions
    innocuoussoul
    @innocuoussoul
    is it possible to filter expected values so the resulting response is only unique?
    { "subject": [ "Fwd: Please complete your assigned training" ], "labelIds": [ "UNREAD", "CATEGORY_PERSONAL", "Label_6568222846829069483", "INBOX" ] }
    {subject:payload.headers[?name=='Subject'].value,labelIds:labelIds}
    i want to filter UNREAD, CATEGORY_PERSONAL, AND INBOX... so only that unique label remains.
    glenveegee
    @glenveegee
    {subject: payload.headers[?name=='Subject'].value, labelIds:map(&(!contains(['UNREAD', 'CATEGORY_PERSONAL', 'INBOX'], @) && [@]) || [] ,labelIds)[]}
    OR
    {subject: payload.headers[?name=='Subject'].value, labelIds:labelIds[*][(!contains(['UNREAD', 'CATEGORY_PERSONAL', 'INBOX'], @) && @) ||[]][]}
    Moisés Jiménez
    @Mo_Jim_twitter

    Hi everyone, I have a question. Is it possible to use the result of a query to search again? For example, say we have the slightly modified example from jmespath.org

    {
    "locations": [
    {"name": "Seattle", "state": "WA"},
    {"name": "New York", "state": "NY"},
    {"name": "Bellevue", "state": "WA"},
    {"Seattle": "Olympia", "state": "WA"}
    ]
    }

    could this query
    {value: @, key: keys(@)[?ends_with(@, 'Seattle')]} | @.value.[@.key]

    return "Olympia"??

    glenveegee
    @glenveegee
    You should be able to pipe your projection but the query is probably not working in the way you want
    What are you actually trying to do
    Moisés Jiménez
    @Mo_Jim_twitter
    so what I want to do is find all the keys in a dictionary that end with a certain string and then use them to extract the values
    glenveegee
    @glenveegee
    something like this?
    locations[?ends_with(state, 'A')].name
    Moisés Jiménez
    @Mo_Jim_twitter
    yeah this gives me just the key names, same as keys(@)[?ends_with(@, 'Seattle')], now I need to use that to extract the values
    glenveegee
    @glenveegee
    Could you write the result of the query you'd like (what you hope to get out). I'm afraid I still don't follow
    Moisés Jiménez
    @Mo_Jim_twitter
    lets say we have this:
    {"key_a_0": "a", "key_b_0": "b", "key_c_1": "c", "key_d_2": d, "key_e_0": "e"}
    and we do
    {value: @, key: keys(@)[?ends_with(@, '_0')]} | @.value.[@.key]
    I would like the result to be
    "a", "b", "e"
    stiller_leser
    @stiller_leser_twitter
    Is it possible to filter by timestamp? Say I have a timestamp in my json and I would only like to retrieve the entries from the last 5 minutes?
    glenveegee
    @glenveegee
    @Mo_Jim_twitter I don't think that's possible. What language are you coding in?
    @stiller_leser_twitter If it's a formatted date then no. If it's in milliseconds then yes but only if you hard code now time
    What language are you working with?
    glenveegee
    @glenveegee
    @jamesls please, please, please can we look at a proposal for an entries function in the spec so we can get object keys and values in the same execution context.
    This isn't the first time this sort of query has arisen and I'm certain it won't be the last
    stiller_leser
    @stiller_leser_twitter
    Hm ok @glenveegee is there a way to only get the last x entries then? Currently my query looks like this: resources[?involvedObject.apiVersion == v1 && involvedObject.kind == Service && involvedObject.name==my-name].{ firstTimestamp: firstTimestamp, lastTimestamp: lastTimestamp, count: count, reason: reason, message: message }
    glenveegee
    @glenveegee
    Yes you can use slices
    I your case search([-x:], [0, 1, 2, 3]) -> [2, 3] where x is a number - the last x entries
    stiller_leser
    @stiller_leser_twitter
    How would I wrap this around my existing search?
    glenveegee
    @glenveegee

    for the last 5 you'd do something like

    resources[?involvedObject.apiVersion == v1 && involvedObject.kind == Service && involvedObject.name==my-name].{ firstTimestamp: firstTimestamp, lastTimestamp: lastTimestamp, count: count, reason: reason, message: message }[-5:]

    ...at least that's what I think you'd have to do

    stiller_leser
    @stiller_leser_twitter
    That's correct. I kept trying to get it too work with search :D Thank you for the help here!
    meschiany
    @meschiany
    Hello, I have a structure query i could not figure out, is this the place?

    {
    "tags": {
    "private_password_reset": {
    "tag_name": "PasswordResetSettings"
    },
    "users": {
    "tag_name": "users"
    }
    }
    }

    result should be: PasswordResetSettings, users

    glenveegee
    @glenveegee
    tags.*.tag_name
    join(', ', tags.*.tag_name)
    meschiany
    @meschiany
    wow, you made it look very easy, thank you
    varajgandhi
    @varajgandhi
    ^[8-9]\d{7}$ this regx not working for json params..mobile number only starting with 8 or 9 and totally 8 digits
    kindly advise anyone
    also single \ throws error in JSON
    glenveegee
    @glenveegee
    Regex search and filter is not part of the jmespath spec as far as I'm aware. Where's this coming from?
    varajgandhi
    @varajgandhi
    am passing value for angular form
    glenveegee
    @glenveegee
    'angular' so I'm assuming JS/TS then what jmespath library are you using?
    What is your input to the jmespath search function and what does your expression look like
    varajgandhi
    @varajgandhi
    image.png
    currently, params take 0-9 as the first digit for a phone number but I need to change the pattern for the starting digit , it must accept either 8 or 9
    glenveegee
    @glenveegee
    Ah. Don't think this has anything to do with JMESPath but fwiw your regex could be written as ^[89][0-9\-]*$. The regex in the image isn't particularly good because it permits a telephone number like 8------------------------5
    You might want to rewrite that regex anyway to make it stricter
    From your initial question I see the regex you started with though ^[8-9]\d{7}$
    varajgandhi
    @varajgandhi
    yes, it doesn't work
    ^[89][0-9]\d{7}*$ also not working
    glenveegee
    @glenveegee
    This is probably because you aren't setting multiline flags
    you should just be able to do [89]\d{7}