schibsted / jslt

JSON query and transformation language
Apache License 2.0
638 stars 120 forks source link

max\min against arrays #351

Open samer1977 opened 6 months ago

samer1977 commented 6 months ago

Hi,

Sorry maybe my brain still thinks the other way but how would you solve this problem: https://github.com/bazaarvoice/jolt/issues/700

I cant think of a way without having to create custom recursive max\min as in:

def max_array(array)

if(size($array)==0) null else if(size($array)==1) $array[0]

else max($array[0],max_array($array[1:]))

vs

{

"minPrice": min([for(.prices).price]) "minPrice": max([for(.prices).price])

}

Thanks

larsga commented 6 months ago

You're right that there is no other way at the moment. max() and min() should perhaps also have single-argument versions that accept an array.