Search array, continue if string is found

I have the following payload:

{
    "code": 200,
    "message": "Request response is successful",
    "data": [
        {
            "origin_info": {
                "trackinfo": [
                    {
                        "checkpoint_date": "2022-07-14 15:40:23",
                        "tracking_detail": "Departed from Facility.",
                        "location": "NL",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-14 11:50:22",
                        "tracking_detail": "Arrived at Sort Facility.",
                        "location": "NL",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-13 16:57:00",
                        "tracking_detail": "Arrived at AIRPORT of Destination",
                        "location": null,
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit004"
                    },
                    {
                        "checkpoint_date": "2022-07-13 12:42:00",
                        "tracking_detail": "Departed from AIRPORT of Origin",
                        "location": null,
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-12 10:33:43",
                        "tracking_detail": "Arrive at international airport to abroad",
                        "location": "CHINA",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-12 08:33:43",
                        "tracking_detail": "Departed Facility In processing center",
                        "location": "Shanghai",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-11 02:14:02",
                        "tracking_detail": "Departed Facility in Shanghai",
                        "location": "Shanghai",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-11 00:33:20",
                        "tracking_detail": "Arrived at Sort Facility Shanghai",
                        "location": "Shanghai",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-09 21:36:44",
                        "tracking_detail": "Arrived at Sort Facility Zhengzhou",
                        "location": "Zhengzhou",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    },
                    {
                        "checkpoint_date": "2022-07-09 10:20:51",
                        "tracking_detail": "Shipment information received Last mile tracking number:00370724762191835799 - Last mile tracking carrier:NO Helthjem",
                        "location": null,
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "notfound001"
                    },
                    {
                        "checkpoint_date": "2022-07-09 02:54:20",
                        "tracking_detail": "Departed from Facility Zhengzhou",
                        "location": "Zhengzhou",
                        "checkpoint_delivery_status": "transit",
                        "checkpoint_delivery_substatus": "transit001"
                    }
                ]
            }
        }
    ]
}

I want the flow to continue only if the string Last mile is found inside one of the tracking_detail.

In this particular payload, it is found inside payload.data[0].origin_info.trackinfo[9].tracking_detail

This string can appear in any element in the array, not always in trackinfo[9] as in this example (however, data is always data[0])

For example the next time the payload arrives it can be in trackinfo[7]. As long as it exists in the payload, I want the flow to continue. If not, I want to route the message somewhere else.

Can anyone help me with this?

you can use JSONata in a switch node.
e.g.

[{"id":"6d572678.76f75","type":"inject","z":"f39a44549a9aa1b8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{     \"code\": 200,     \"message\": \"Request response is successful\",     \"data\": [         {             \"origin_info\": {                 \"trackinfo\": [                     {                         \"checkpoint_date\": \"2022-07-14 15:40:23\",                         \"tracking_detail\": \"Departed from Facility.\",                         \"location\": \"NL\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-14 11:50:22\",                         \"tracking_detail\": \"Arrived at Sort Facility.\",                         \"location\": \"NL\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-13 16:57:00\",                         \"tracking_detail\": \"Arrived at AIRPORT of Destination\",                         \"location\": null,                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit004\"                     },                     {                         \"checkpoint_date\": \"2022-07-13 12:42:00\",                         \"tracking_detail\": \"Departed from AIRPORT of Origin\",                         \"location\": null,                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-12 10:33:43\",                         \"tracking_detail\": \"Arrive at international airport to abroad\",                         \"location\": \"CHINA\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-12 08:33:43\",                         \"tracking_detail\": \"Departed Facility In processing center\",                         \"location\": \"Shanghai\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-11 02:14:02\",                         \"tracking_detail\": \"Departed Facility in Shanghai\",                         \"location\": \"Shanghai\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-11 00:33:20\",                         \"tracking_detail\": \"Arrived at Sort Facility Shanghai\",                         \"location\": \"Shanghai\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-09 21:36:44\",                         \"tracking_detail\": \"Arrived at Sort Facility Zhengzhou\",                         \"location\": \"Zhengzhou\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     },                     {                         \"checkpoint_date\": \"2022-07-09 10:20:51\",                         \"tracking_detail\": \"Shipment information received Last mile tracking number:00370724762191835799 - Last mile tracking carrier:NO Helthjem\",                         \"location\": null,                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"notfound001\"                     },                     {                         \"checkpoint_date\": \"2022-07-09 02:54:20\",                         \"tracking_detail\": \"Departed from Facility Zhengzhou\",                         \"location\": \"Zhengzhou\",                         \"checkpoint_delivery_status\": \"transit\",                         \"checkpoint_delivery_substatus\": \"transit001\"                     }                 ]             }         }     ] }","payloadType":"json","x":250,"y":40,"wires":[["ebd83606.62a28"]]},{"id":"ebd83606.62a28","type":"switch","z":"f39a44549a9aa1b8","name":"","property":"true in payload.data[*].origin_info.trackinfo[*].$contains($lowercase($.tracking_detail),\"last mile\")","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":40,"wires":[["a39402cc.ecc9d"]]},{"id":"a39402cc.ecc9d","type":"debug","z":"f39a44549a9aa1b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":40,"wires":[]}]
true in $$.payload.data[*].origin_info.trackinfo[*].$contains(
   $lowercase($.tracking_detail),
   "last mile"
)

Works perfecly, thanks a bunch!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.