JSON: Split Array and Objects

1,573 views
Skip to first unread message

Seb

unread,
Nov 15, 2017, 9:59:38 AM11/15/17
to Node-RED
Good day,

a HTTP request gives me several arrays with objects.

How to split those objects from all arrays into single requests?


Thank you!


msg.payload : Object
object
firstResult0
maxResultHits50
hitsarray[50]
[0 … 9]
0object
1object
2object
3object
4object
5object
6object
7object
8object
9object
[10 … 19]
[20 … 29]
[30 … 39]
[40 … 49]
totalHits574642

steve rickus

unread,
Nov 15, 2017, 10:09:55 AM11/15/17
to Node-RED
Have you tried using the split node? It can turn a msg.payload array into a stream of msg objects with each element in its own payload.
Since the split node expects the input msg to hold the array in msg.payload, wire in a change node before the split to "Set" msg.payload "to" msg.payload.hits

Seb

unread,
Nov 15, 2017, 10:18:18 AM11/15/17
to Node-RED
Amazing - thanks for the quick help!

Julian Knight

unread,
Nov 15, 2017, 12:33:16 PM11/15/17
to Node-RED
Just a note to say that the output you showed are not quite how they seem from the debug output. You only have 1 array of objects there, they are split only to keep the display performant. In actuality, that is a single array of objects.
Reply all
Reply to author
Forward
0 new messages