# Array parsing question

**URL:** <https://discourse.nodered.org/t/array-parsing-question/65049>\
**Category:** General\
**Created:** [13 July 2022 12:55 UTC](https://discourse.nodered.org/t/array-parsing-question/65049 "2022-07-13T12:55:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobamoba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mobamoba/32/25401_2.png) [@mobamoba](https://discourse.nodered.org/u/mobamoba)\
**Post date:** [13 July 2022 12:55 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/1 "2022-07-13T12:55:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 July 2022 13:01 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/2 "2022-07-13T13:01:18Z")

</div>

> [@mobamoba](#):
>
> Is there a way parse an array without a function node

Yes - split node

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2022 13:02 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/3 "2022-07-13T13:02:43Z")

</div>

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

```auto
$$.payload.value.anothervalue

```

example flow

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![mobamoba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mobamoba/32/25401_2.png) [@mobamoba](https://discourse.nodered.org/u/mobamoba)\
**Post date:** [13 July 2022 14:17 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/4 "2022-07-13T14:17:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2022 14:35 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/5 "2022-07-13T14:35:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mobamoba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mobamoba/32/25401_2.png) [@mobamoba](https://discourse.nodered.org/u/mobamoba)\
**Post date:** [13 July 2022 14:53 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/6 "2022-07-13T14:53:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [13 July 2022 16:33 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/7 "2022-07-13T16:33:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2022 16:56 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/8 "2022-07-13T16:56:59Z")

</div>

> [@mobamoba](#):
>
> payload.properties.apparentTemperature.values[0].validTime

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

---

<div class="post-metadata">

**Author:** ![mobamoba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mobamoba/32/25401_2.png) [@mobamoba](https://discourse.nodered.org/u/mobamoba)\
**Post date:** [13 July 2022 17:33 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/9 "2022-07-13T17:33:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 September 2022 17:33 UTC](https://discourse.nodered.org/t/array-parsing-question/65049/10 "2022-09-11T17:33:43Z")

</div>

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