Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    glenveegee
    @glenveegee
    map(&contains(@, 'a'), (metadata.olo_order.tags) == 'array' && metadata.olo_order.tags || [metadata.olo_order.tags])
    Brandon Max
    @bmax
    and @hell-racer it's || or | for the doesn't exist?
    hell-racer
    @hell-racer
    ||
    glenveegee
    @glenveegee
    | is a pipe to a new expression
    Brandon Max
    @bmax
    got it.. okay let me try to implement your solution glen
    glenveegee
    @glenveegee
    Be warned it doesn't account for null but you get the idea
    Brandon Max
    @bmax
        ((metadata.olo_order.custom_properties.tags || `[]`) | contains(map(&contains(toLowerCase(@), `first`), @), `true`))
    here is what I have now
    so basically I can just add (metadata.olo_order.tags) == 'array' && after the first | ?
    glenveegee
    @glenveegee
    This will work for all cases I. think (metadata.olo_order.tags || '') | map(&contains(@, 'a'), (@) == 'array' && @ || [@])
    Not sure if you need it but it probably won't handle nulls in the array
    Can be fixed
    hell-racer
    @hell-racer
    [metadata.olo_order.tags][] | [?contains(@, 'first')]
    Brandon Max
    @bmax
    the way I had previously, the contains with a map and then another contains was to be able to lowerCase each value inside of the array.
    hell-racer
    @hell-racer
    [metadata.olo_order.tags][] | [?contains(toLowerCase(@), 'first')]
    This should handle string, array and null
    Brandon Max
    @bmax
    (([metadata.olo_order.custom_properties.tags][]) | contains(map(&contains(toLowerCase(@), `first`), @), `true`)
    this actually works..
    thank y'all so much
    wow that works.
    @hell-racer @glenveegee
    hell-racer
    @hell-racer
    Maybe remove some round brackets
    ([metadata.olo_order.custom_properties.tags][] | contains(map(&contains(toLowerCase(@), `first`), @), `true`)
    glenveegee
    @glenveegee
    Forgive my ignorance chaps. Where is toLowerCase coming from?
    That ain't JMESPath
    hell-racer
    @hell-racer
    @glenveegee didn't you miss type()? As for toLowerCase() - maybe he uses some custom implementation.
    glenveegee
    @glenveegee
    I did
    glenveegee
    @glenveegee
    @hell-racer Like the flatten to normalise
    [metadata.olo_order.tags][] | contains(@, `first`)
    Great suggestion
    hell-racer
    @hell-racer
    :)
    Brandon Max
    @bmax
    jmespath-plus @glenveegee
    glenveegee
    @glenveegee
    Hahaha. That's the one I wrote
    Good choice
    tee hee
    Oh wait
    Actually I wrote @metrichor/jmespath-plus. Even better with almost all of lodash built in
    FWIW: I wrote a playground with all the JS and TS implementations
    If you want to compare them
    Brandon Max
    @bmax
    @glenveegee AWESOME!! I actually have a larger question: Is there any better technology (not that jmespath isn't great) but just something a little bit easier to use for searching and or contains on a JSON blob? Like elasticsearch does this stuff really well but it's kind of hard to get the json blob into an ES instance within a fast enough time frame. Maybe a templating system?
    glenveegee
    @glenveegee
    Great question but I'm afraid I don't have a good answer for that.
    You'll know there are other similar libs out there all doing things slightly differently (thinking JSONPath, jq, lodash etc).
    Some prioritise a more natural syntax. Others offer search only (perhaps with a few utility functions) but no data transforms
    JMESPath (others feel free to chime in) does search and data transforms but if you don't need the transforms it might be overkill
    Brandon Max
    @bmax
    i guess I do toLowerCase but that's really it lol
    glenveegee
    @glenveegee
    I will say that it's pretty damn fast and that's (in part made possible) due to a fundamental design choice that it only offers access to child nodes
    Brandon Max
    @bmax
    the templating syntax is just so complicated lol
    glenveegee
    @glenveegee
    Can't disagree but FWIW it get's easier. Lurking around here helps.
    Brandon Max
    @bmax
    appreciate y'all help so much either way @glenveegee @hell-racer
    hell-racer
    @hell-racer
    I don't know why, but working with JmesPath is so much fun
    Tymac
    @dreftymac_twitter
    @hell-racer agreed