Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Chip Zoller
    @chipzoller
    Didn't realize the queries work through piped expressions like that.
    hell-racer
    @hell-racer
    So all works? )
    Chip Zoller
    @chipzoller
    I think so, yes.
    hell-racer
    @hell-racer
    Nice )
    Chip Zoller
    @chipzoller
    But is this the "right" way to build the query? Or is there something better?
    hell-racer
    @hell-racer
    I think this is fine. Unless there are some items like 'sleep1' which will count too.
    Chip Zoller
    @chipzoller
    That's true and I'm kind of confused why it would match substring in that case when normally it doesn't.
    hell-racer
    @hell-racer
    Because of contains() :)
    So maybe spec.containers[].lifecycle.preStop.exec.command[] | [?@ == 'sleep'] | length(@) is better fit.
    Chip Zoller
    @chipzoller
    Perfect, thanks!
    Chip Zoller
    @chipzoller

    Ok, got another interesting JMESPath question. Given a collection like this

    $ yq e pod.yaml -j | jp "spec.containers[].securityContext.capabilities.drop[*]"
    [
      [
        "SETUID",
        "CAP_FOO_BAR"
      ],
      [
        "NET_RAW"
      ]
    ]

    Is there a query that can be written in JMESPath that returns an overall true/false if a given string isn't found in each of the arrays? For example, I'm looking for the string NET_RAW in each of the array entries. I want to see a false if not every one contains that entry.

    hell-racer
    @hell-racer
    Hi!
    You could flatten it and then check it via contains().
    [][][][][] | contains(@, 'NET_RAW')
    Is this good enough for you?
    (I've added several flatten operators just in case, in this particular case one is enough)
    glenveegee
    @glenveegee
    Gnarly!
    hell-racer
    @hell-racer
    ?
    Ah I see I'm doing it wrong :)
    glenveegee
    @glenveegee
    heres a more verbose two-step option but doesn't account for nested arrays deeper than what's in your example like @hell-racer does
    map(&contains(@, 'NET_RAW'), @) | contains(@, `true`)
    hell-racer
    @hell-racer
    Your expression returns true if at least one array contains NET_RAW, but he asked it should return true if ALL of then contain it (if I understand correctly). My expression doesn't fit too, I understood the task incorrectly.
    So maybe just change it to map(&contains(@, 'NET_RAW'), @) | !contains(@, `false`)
    glenveegee
    @glenveegee
    Now that I read it again me interpretation of the question was wrong
    Yes the inverted logic should do it
    hell-racer
    @hell-racer
    But itsn't it possible to do it without map() though?
    It should be possible with projection
    glenveegee
    @glenveegee
    yup
    hell-racer
    @hell-racer
    !contains([*].contains(@, 'NET_RAW'), `false`)? :)
    glenveegee
    @glenveegee
    [*].contains(@, 'NET_RAW')| contains(@, `false`)
    hell-racer
    @hell-racer
    yup
    glenveegee
    @glenveegee
    Nice to have someone else to bounce off
    hell-racer
    @hell-racer
    :)
    Chip Zoller
    @chipzoller

    Hey thanks @hell-racer and @glenveegee for once again helping me out here. I tried the [*].contains(@, 'NET_RAW')| contains(@,false) option from glen but I may not be understanding it properly. I get false even if each container's drop[] array does contain NET_RAW. Also, jp doesn't seem to work when I use backticks to enclose the booleans (if everything is in double-quotes). Does this impact its evaluation?

    $ yq e pod.yaml -j | jp "spec.containers[].securityContext.capabilities.drop[*].contains(@, 'NET_RAW') | contains(@, 'false')"
    false

    And just to check the projection by eliminating the filter:

    $ yq e pod.yaml -j | jp "spec.containers[].securityContext.capabilities.drop[*].contains(@, 'NET_RAW')"
    [
      [
        false,
        false,
        true
      ],
      [
        true,
        false
      ]
    ]
    62 replies
    hell-racer
    @hell-racer
    I think it's better to test expressions on https://jmespath.org/, so we're on the same page. E.g. I don't use jp and can't test my expressions there.
    caedh121
    @caedh121
    hi, totally newbie here, trying to filter a property from an azure user using azure cli, found this possible path a few minutes ago, can I get help here?
    1 reply
    caedh121
    @caedh121
    image.png
    NadavRothVerte
    @NadavRothVerte
    hi guys.
    is there a way to get the index of the current node @?
    1 reply
    Chip Zoller
    @chipzoller
    Hey again, friends. Have another question related to finding of strings.
    Assuming there is an input array of strings, is it possible to write a JMESPath query that searches a destination array of strings and can detect if ANY of the strings in the input are found in the destination?
    Example:
    Given ["red","blue"] are any of those strings found in ["black","orange","yellow","blue","green"]
    Chip Zoller
    @chipzoller
    The answer would be "true" in the above case.
    1 reply
    Chip Zoller
    @chipzoller
    @glenveegee or @hell-racer if you have any thoughts on above would be great.
    glenveegee
    @glenveegee
    I got something.... but nobody is going to like it ;)
    I haven't been able to do it without an assumption of either the query or target array of strings
    20 replies
    octaviand2
    @octaviand2
    Hi, is there any limitation in jmespath in terms of size (in characters) of the json? I have a json with about 180.000 characters. Thank you.
    2 replies
    Ajay Vohra
    @scienceorbust1_twitter
    How does one check the official compliance level for a new JmesPath library? I created this JmesPath library for Hacklang a few days ago and would like to check the official compliance level per specification, and fix any issues of compliance, if they exist: https://github.com/ajayvohra2005/hack-jmespath
    glenveegee
    @glenveegee
    There should be a test suite in the reference implementation repositories on github. Depending on the language you might find one already done. Lookout for a file ny the name of compliance
    For example
    1 reply