Skip to main content
Version: Streamsheets 3.0

Payload Looping

Looping inbox payloads allows looking at payload elements individually.

Inbox Loop

Inbox messages can consist out of different objects. There are the regular parameters like boolean, number or string elements, which are holding the actual information, and there are structural elements like "dictionaries" and "arrays". The structural elements are ordering the information in different hierarchies. While "dictionaries" only serve as folder elements to organize message data in different levels, "arrays" usually follow a certain style and represent an ordered list of values. They repeat the same form for a certain amount of time. For example, if a message should hold different information for the same parameters an array would be the perfect choice.

Simple example: You could structure multiple sensor information from the same parameter in one message. Let's say you have three sensors, who all measure temperature: Sensor 1 measured 10°C, Sensor 2 measured 20°C and Sensor 3 measured 12°C.

A JSON object capturing this information would look like this:

[    {
} ]

In a Streamsheet Inbox this would look like this:

JSON Array in Streamsheets

In Streamsheets, it is now possible to loop these arrays. When looping an array, every array object gets treated as part of a single message. Usually, one message takes one step to be processed. Adding a loop to our example message would now result in three steps. Streamsheets would read only one of the three information blocks in every step. There are two main reasons why this seems practical.

  1. The array is filled with messages you want to process one after another.
  2. The array varies in size, and you never know how big an array could get. So adding simple READ() functions does not cut it.

Adding a loop element is quit simple. Wait for one message to arrive in the inbox, right-click on the top array element and select "Set Loop Element". It is also possible to set the loop element in the Inbox settings. There you can also add the option "recursively", if you not just want to loop through an array, but want to loop through more than just one level of an "array" or even "dictionary" object.



right click on "Data" to set loop element


Set the Loop in the Inbox settings or in the payload.


Now the incoming message will be treated in three singular steps. You may notice that dragging and dropping the Payload items creates a different function than usual.

In a loop:


No loop:


The loop function is not fixed upon the "0" element and reads the payload information for every loop step. This way, one READ() function covers all loop steps.