Looping over HTTP response

Hi,
I am trying to use for loop over HTTP response. Sample JSON of HTTP response is attached below.
Case: I got an array of object as http response, now I have to check the status of each object and if all the status are 1 my function should return 1 else if any of the status is 0 it should return 0.

I tried writing code my self but it is not iterating it properly.

Sample HTTP response:

[
[
{
"name": "Mustafa",
"surname": "Ali",
"status": "1"
},
{
"name": "Piyush",
"surname": "Dharpure",
"status": "0"
},
{
"name": "Rishith",
"surname": "Agarwal",
"status": "1"
}
]
]

Function node:

cant you use the IF node?

Size of array can be variable, so can I use IF in that case?

Hey @Mustafa_Ali,

The incoming data should follow the n8n data structure (I suggest you take a look here:Transforming Data | Docs). Since you’re using the HTTP Request node, you can set Split Into Items option to true.

Then as @RedPacketSec suggested, you can use the IF node to check the condition. The IF node will check for all the incoming items.

When I will use If over all the item it will separate the object with 1,0 status. I want is a final 1 or 0 output based on the status of all the objects.

After setting up the Split Into Items option, you can use the Function node. The main thing here is to transform the data structure of the incoming data. The Split Into Items option transforms the data structure which allows you to loop through the data.

1 Like

Hey @Mustafa_Ali,

Did the solution work for you? Let us know if you’re still stuck with this issue :slight_smile:

Hello @harshil1712 ,
It worked perfectly. Thanks for all the help :grinning:

1 Like