Hi, I am trying to make a flow to read a JSON and write it to a csv file.
The JSON has an object that contains an array and what I am trying to do is to make a loop to write each object of the array in a line of the file.
I need to extract in each execution of the node, the data: msg.payload.data.dataList[index].oltId
If in index, I put the value 0, it works correctly, but I want that value to change to extract all the array objects.
The function that I have created has the code:
var listaItems = flow.get('listaItems');
var estado = msg.payload.status;
var api = msg.payload.data.api;
var oltId = msg.payload.data.dataList[listaItems].oltId;
var oltName = msg.payload.data.dataList[listaItems].configuration.oltName;
var oltIP = msg.payload.data.dataList[listaItems].configuration.oltIP;
listaItems --;
flow.set('listaItems',listaItems);
msg.payload.estado = estado;
msg.payload.api = api;
msg.payload.oltId = oltId;
msg.payload.oltName = oltName;
msg.payload.oltIP = oltIP;
return msg;
The error I have is: TypeError: Cannot read property 'oltId' of undefined.
If instead of doing it that way, I simply put a number in the index, it works correctly:
var estado = msg.payload.status;
var api = msg.payload.data.api;
var oltId = msg.payload.data.dataList[0].oltId;
var oltName = msg.payload.data.dataList[0].configuration.oltName;
var oltIP = msg.payload.data.dataList[0].configuration.oltIP;
msg.payload.estado = estado;
msg.payload.api = api;
msg.payload.oltId = oltId;
msg.payload.oltName = oltName;
msg.payload.oltIP = oltIP;
return msg;
How can I use a variable in the array index?.
Thank you very much