Search code examples
javascriptnode-redpayload

How can I change a payload array into a payload object in Node Red?


In Node Red I have a message that has an array of three values as payload and I want to assign those values to three different properties of a payload object. How can I do that? Thank you


Solution

  • You can't directly move the array elements to msg.paload.X because you can't add arbitrary fields to the existing array objects.

    So you'll need to move the array to a temp field first. You will also have to only ever move the first ([0]) element in the array because it will get shorter on every move as the first element is pop'd from the array.

    enter image description here

    And finally delete the temp filed.