Array parsing question

Is there a way parse an array without a function node? For example, if the data I'm receiving is in the form: msg.payload.value[0-9].anothervalue, can I split it and grab the 10 anothervalues without doing a for loop in a function? Thanks.

Yes - split node

msg.payload --> split --> change node --> join --> result

Yes by using Jsonata in a change node.
The expression would be something like

$$.payload.value.anothervalue

example flow

[{"id":"39a194fd.20cbcc","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"value\":[{\"another_value\":1},{\"another_value\":2},{\"another_value\":3}]}","payloadType":"json","x":140,"y":2180,"wires":[["8ef7ccd6.f2584"]]},{"id":"8ef7ccd6.f2584","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.value.another_value","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":2220,"wires":[["7dae4206.4a76f4"]]},{"id":"7dae4206.4a76f4","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":2080,"wires":[]}]

Sorry I'm not clear how that would work. The msg.payload looks like this:
msg

  • payload
    -- values
    --- value [0 ... 9]
    ---- 0
    ----- string
    ----- string2
    ---- 1 (etc etc up to 9)
    --- value [10 ... 19]
    ---- etc etc up to the end of the array

So I'm trying to figure out if there's a way for NR to get me all those string and string2 without using a for loop in a function node.

I understand change node and splitting; what I don't understand is the formatting (if it exists) like if I want to extract all the values of "string" from above, is the Change Node set msg.payload to... to what? msg.payload.values.value[XXXX].string ? Thanks.

best to use the copy value button in debug node, it appears when you hover mouse to right of payload object. Then paste here using </> botton.
Then supply the output you want from that array, i.e.[string,string1,string,string1]
or [[string,string1],[string,string1]], etc. Then it will be clear what the input is and what the output should look like.

Also do you wish to do this in a function node or outside.

Here - payload.properties.apparentTemperature.values has 140 array values broken up into chunks of 10 ([0-9], [10-19], etc.) starting with payload.properties.apparentTemperature.values[0]. Each value in the array contains a timestamp which looks like this payload.properties.apparentTemperature.values[0].validTime.

I'm trying to extract the 140 validTime values without involving a Function node at all. Is there a way to do that or is it impossible in NR without writing a function?

I don't understand the point not to use a function. Unless you like to make your Life harder

2 Likes

If that is the valid path, then the jsonata expression to use in a change node would be
$$.payload.properties.apparentTemperature.values.validTime
and it would return 140 validTime values in an array

Again if you supply a sample data and what you want outputted, then i would provide an example

That in conjunction with split worked great. I don't know Jsonata so it didn't even occur to me that it might be an option for my use case so thanks.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.