We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Iterating over Array.Object

djfrey
Tera Contributor

I'm having issue with Process Automation using a 'for' loop to access items in an object array. My output object looks as below and varies in number of objects returned each time the data is fetched:

{
    "resultArray": [
        {
            "device_model": "TestString",
            "city": "Test City",
            "ip": "8.8.8.8",
            "device_type": "web",
            "geo": "US",
            "protocol": "tcp",
            "hostname": "test.hostname.com",
            "port": "443",
            "tag": "web",
            "device_vendor": "Test Vendor",
            "region": "Test Country",
            "asn": "1234",
            "timestamp": "2022-01-31 07:13:28"
        },
        {
            "device_model": "TestString",
            "city": "Test City",
            "ip": "8.8.8.8",
            "device_type": "web",
            "geo": "US",
            "protocol": "tcp",
            "hostname": "test.hostname.com",
            "port": "443",
            "tag": "web",
            "device_vendor": "Test Vendor",
            "region": "STATE",
            "asn": "1234",
            "timestamp": "2022-01-31 08:33:54"
        }
    ]
}

 

When I utilize a 'for each item in resultArray' I am returned an empty object, rather than each object in the array that I would like to further automate over. I believe its the manner in which I'm outputting the script data, but have tried a number of iterations with no success. My settings in the script and flow are as below:

find_real_file.png

 

find_real_file.png

1 REPLY 1

Hitoshi Ozawa
Giga Sage

In the script, JSON.stringify() will convert the json object into a String. So "output" should be a String instead of an Array.Object.

If setting variable "output" as a Array.Object, just don't stringify the resultArray.

outputs.output = resultArray;