Result Parser syntax for JSON arrays

Hello!

I had trouble using the result parser on an array earlier and wondered if I misunderstood the syntax somehow. My json was something like this:

{
    "weekdays": [
        {
            "dayOfWeek": "Monday",
            "dayNumber": 1
        },
        {
            "dayOfWeek": "Tuesday",
            "dayNumber": 2
        },
        {
            "dayOfWeek": "Wednesday",
            "dayNumber": 3
        }
    ]
}

The code

rawResponseData.weekdays.test = "hello"
return rawResponseData

did not add a test property with the value “hello” to every weekday as expected. Adding a single test property outside of the array worked as expected with

rawResponseData.test = "hello"
return rawResponseData

I was able to find a workaround using update object after the result mapping, but I was curious how one would use the parser on arrays in the future.

Hi!

weekdays is an array of objects. So you need to break it down to how to add an property to all objects of an array.

To add a property to each object, you may do this:

for (let i = 0; i < rawResponseData.weekdays.length; i++) {
    rawResponseData.weekdays[i].test = "hello";
}
return rawResponseData;

PS: Ninjatrick for code-related topics: If you copy your whole post to Gemini (2.5 pro model) it will give you this answer

Thank you, that makes perfect sense. It is a compliment to the elegance of Appfarm that I didn’t even consider my problem in a coding context. :laughing:

1 Like