[array help] get a collection field value containing the sub-collection with the lowest field value from an array

  • HTTP request returns data with the following structure:
[
    {
        "statusCode": 200,
        "headers": [
            {
                "name": "accept-ranges",
                "value": "bytes"
            },
            {
                "name": "content-type",
                "value": "application/json"
            },
            {
                "name": "last-modified",
                "value": "Wed, 14 Feb 2024 21:05:08 GMT"
            },
            {
                "name": "vary",
                "value": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers"
            },
            {
                "name": "x-current-token-count",
                "value": "199"
            },
            {
                "name": "x-envoy-upstream-service-time",
                "value": "2566"
            },
            {
                "name": "x-next-replenishment-time",
                "value": "0"
            },
            {
                "name": "x-tb",
                "value": "1"
            },
            {
                "name": "x-tb-optimization-total-bytes-saved",
                "value": "0"
            },
            {
                "name": "content-length",
                "value": "1299"
            },
            {
                "name": "expires",
                "value": "Wed, 14 Feb 2024 21:05:08 GMT"
            },
            {
                "name": "cache-control",
                "value": "max-age=0, no-cache, no-store"
            },
            {
                "name": "pragma",
                "value": "no-cache"
            },
            {
                "name": "date",
                "value": "Wed, 14 Feb 2024 21:05:08 GMT"
            },
            {
                "name": "connection",
                "value": "close"
            }
        ],
        "cookieHeaders": [],
        "data": {
            "data": {
                "estimates": [
                    {
                        "name": "SMART_POST",
                        "displayName": "FedEx Ground Economy",
                        "deliveryDate": "2024-02-20T23:59:00.000Z",
                        "estimatedRate": {
                            "amount": 9.05,
                            "currency": "USD"
                        },
                        "serviceTypeGroupName": "FEDEX_GROUND",
                        "serviceTypeGroupDisplayName": "FedEx Ground",
                        "isDeliveryPromiseFulfilled": true,
                        "carrierName": "FedEx",
                        "carrierDisplayName": "FedEx"
                    },
                    {
                        "name": "FEDEX_GROUND",
                        "displayName": "FedEx US Ground",
                        "deliveryDate": "2024-02-19T23:59:00.000Z",
                        "estimatedRate": {
                            "amount": 10.69,
                            "currency": "USD"
                        },
                        "serviceTypeGroupName": "FEDEX_GROUND",
                        "serviceTypeGroupDisplayName": "FedEx Ground",
                        "isDeliveryPromiseFulfilled": true,
                        "carrierName": "FedEx",
                        "carrierDisplayName": "FedEx"
                    },
                    {
                        "name": "FEDEX_2_DAY",
                        "displayName": "FedEx 2Day",
                        "deliveryDate": "2024-02-16T17:00:00.000Z",
                        "estimatedRate": {
                            "amount": 11.05,
                            "currency": "USD"
                        },
                        "serviceTypeGroupName": "FEDEX_EXPRESS",
                        "serviceTypeGroupDisplayName": "FedEx Express",
                        "isDeliveryPromiseFulfilled": true,
                        "carrierName": "FedEx",
                        "carrierDisplayName": "FedEx"
                    },
                    {
                        "name": "FEDEX_EXPRESS_SAVER",
                        "displayName": "FedEx Express Saver",
                        "deliveryDate": "2024-02-19T17:00:00.000Z",
                        "estimatedRate": {
                            "amount": 11.05,
                            "currency": "USD"
                        },
                        "serviceTypeGroupName": "FEDEX_EXPRESS",
                        "serviceTypeGroupDisplayName": "FedEx Express",
                        "isDeliveryPromiseFulfilled": true,
                        "carrierName": "FedEx",
                        "carrierDisplayName": "FedEx"
                    }
                ]
            }
        },
        "fileSize": 1299
    }
]
  • I can find the lowest amount in the estimatedRate collection
  • but I need to find associated ā€˜nameā€™ field value from the collection that contains the matching estimatedRate

The function:

{{min(map(map(39.data.data.estimates; ā€œestimatedRateā€); ā€œamountā€))}}

Returns the lowest amount value, but I donā€™t know how to find the ā€œSMART_POSTā€ name in the corresponding collection that contained it.

NVM I solved it with:

{{get(sort(39.data.data.estimates; ā€œascā€; 39.data.data.estimates.estimatedRate.amount); ā€œ1.nameā€)}}

1 Like

You can post the answer as a reply to your thread, so you can mark it as solved so that the bot will close it after a while.

3 Likes

NVM I solved it with:

{{get(sort(39.data.data.estimates; ā€œascā€; 39.data.data.estimates.estimatedRate.amount); ā€œ1.nameā€)}}

3 Likes

Hi @skanfklwef :blob_wave:

Awesome to hear that you managed to resolve this on your own :clap:

Thanks a lot for remembering to stop by the community and sharing what did the trick for you. We all 100% appreciate it! :pray:

1 Like