Hello guys,
I need a helping hand on quite simple flow. While I am weak on Javascript and don’t want to use OpenAI for data transformation, maybe some of you will have a solution.
I need to split it and run each through a FILTER to remove those which doesn’t meet the boolean condition. In this sample, only one object has TRUE condition and at the end of the flow, I want to run each of TRUEs separately to the next nodes.
Okay, then the heavy lifting is to map your data to a proper list.
This is currently only possible with a bit of code.
After having a strutured list it is easy to filter for your attribute.
This is the clunky code to do the transformation:
let returnObjects = [];
// Loop over input items and add a new field called 'myNewField' to the JSON of each one
for (const item of $input.all()) {
const nestedObjects = Object.keys(item.json)
.filter(key => typeof item.json[key] === 'object')
.map(key => ({ id: key, ...item.json[key] }))
.map(object => {
object.nestedData = {
"checkIn": item.json.checkIn,
"lastNight": item.json.lastNight,
"checkOut": item.json.checkOut,
"propId": item.json.propId
}
return object;
});
returnObjects = [...returnObjects, ...nestedObjects]
}
return returnObjects;