Hi Octavio,
I believe 30 is tying the variables together and V is for Value, U for Unit and N for name? In this case you could use the following parser:
function ParsePayload(input_payload) {
// Create a dictionary to hold the combined data
const combinedData = {};
// Iterate over each item in the input payload
input_payload.forEach(item => {
// Extract the group number and type (n, u, v) from the variable name
const [group, type] = item.variable.split(‘_’);
// Initialize the group in the dictionary if it doesn’t exist
if (!combinedData[group]) {
combinedData[group] = { group: item.group };
}
// Depending on the type, assign the value to the correct property
if (type === ‘n’) {
combinedData[group].variable = item.value;
} else if (type === ‘u’) {
combinedData[group].unit = item.value;
} else if (type === ‘v’) {
combinedData[group].value = item.value.toString(); // Convert to string to match expected output
}
});
// Convert the dictionary to an array of the combined data objects
const output_payload = Object.values(combinedData);
return output_payload;
}
// Call the ParsePayload function with the example input
payload = ParsePayload(payload);
Hope this helps! 