Hi,
I want to find the object_id that correspond to the lowest amount value in the sample array below. When I make an HTTP request, the response stores the amount value in string instead of number. I can’t nest array formulas to get the lowest amount value due to this. Is there a way to do this without iterating the array, converting the text into number, aggregate to a new array, then sorting for the lowest value? The other answers I found worked by looking for a fixed service value, which doesn’t apply here.
Example:
"rates": [
{
"object_id": "133abd2f1bb4458582410a97bb6185be",
"amount": "12.02",
"provider": "UPS",
"service": "Ground"
},
{
"object_id": "1039a64bcbfd4ab28dd0faf8939e8a13",
"amount": "6.40",
"provider": "USPS",
"service": "Ground Advantage"
},
{
"object_id": "37655124dca34d60938a5473755b0a80",
"amount": "37.09",
"provider": "UPS",
"service": "Express"
}
]
Hi thank you for the output of your data makes life easy.
I created a JSON module with your data
mapped the amounts and used min to get the lowest number in the array
using this function:
{{min(map(21.rates; “amount”))}}
thats it!
Please mark as solution if this works for you. Thank you!
I think the issue here is that the amounts are stored as text, will they still sort properly?
2 Likes
Yes, the issue is the text sorting will create the following order:
[
"amount": "103.99",
"amount": "11.99"
]
If I just used the first value from the array, it will not be the lowest.
My process with stuff like this is similar to what you mentioned.
Iterate rates, aggregate into a new JSON which just consists of the decimal version of the amount, parse that JSON, aggregate into an array, then you should be able to use the min() function to find the lowest.
With the lowest value, use that with map() to get() the object_id, provider, and service from the original array.
1 Like
To answer your question, nope, there is no way to do this without Iterating, as your values are currently strings, which cannot be sorted as numbers without some form of conversion.
Join the Make Fans Discord server to chat with other makers!
2 Likes
If you really don’t want to you can throw the array into ChatGPT and ask it to give you the lowest value. Assuming you have an open api account and want to pay for tokens. This should not be expensive to ask this question. @skanfklwef.
2 Likes