Function for parsing an Array of data

Hello,
I have an mqtt topic message in json with one key that has as its value an array of data that represents telemetry readings from devices attached to a controller. For this message each devices telemetry reading is a slot in the array.
ex.
{
“controllerID”: 6,
“devicetelemetry”:[23,34,344,22,67]
}

I am looking for a best practice in Stream Sheets to parse this array. It is not clear this is supported without treating the array as a text string and parsing it with split. This seems less than optimal.

thanks in advance for your reply.

Hi MrAbsaroka,

Streamsheets does support arrays. In your case it would look like this:

image

{“controllerID”:6,“devicetelemetry”:[23,34,344,22,67]}

To parse the JSON we use the parser from node/javascript.

If the Inbox parses your message as a string there could be two problems:

  1. you don´t send it as a JSON the parser understands
  2. the Consumer is set to “String”.

If this does not help, can you send me a screenshot of your Inbox (with the message in it), an export of your machine and maybe describe the way you are sending the message to the inbox. :slight_smile:

Cheers

Tizian

thank you for your prompt reply and clarification. the problem was indeed how I was structuring my test data generator. Your example clarified how to build the json object so Streamsheets would see it correctly.

I should point out the the mqtt message would not work as follows to achieve the result.

for your example I think the message in mqtt would need to be formatted as:
{
“controllerID”:6,
“devicetelemetry”:{“1”:23,“2”:34,“3”:344,“4”:22,“5”:67}
}

So at the point an actual array in the place of the value of the json object does not see to have a solution.

Hi MrAbsaroka

The numbers 0,1,2,3,… are only used to describe the array elements in a visual form.
This is the way Streamsheets displays every array.

If data is displayed differently the parser did not interpret it as an array (JSON).
If I understand correctly you still have this problem.
Can you send me an export of what you have done so far and describe how you generate/send your test data. :slight_smile:

Cheers