# Split JSON Object Array

**URL:** <https://discourse.nodered.org/t/split-json-object-array/92865>\
**Category:** General\
**Created:** [2 November 2024 11:33 UTC](https://discourse.nodered.org/t/split-json-object-array/92865 "2024-11-02T11:33:18Z")\
**Posts on this page:** 16\
**Page:** 2

<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:** [2 November 2024 13:33 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/21 "2024-11-02T13:33:19Z")

</div>

thank you for providing the data.

Here are 3 ways you can worth with it. The V1 is what I said to do on my very first post.

![chrome_N7GTYvBNgX](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/ebd60567bc920f5b6d9dc83362b1e29b642b22c7.gif)

Demo flow

[demo.json](https://discourse.nodered.org/uploads/short-url/2towWf87Ng8KIiJxXzIulx1xyrM.json) (58.2 KB)

---

<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:** [2 November 2024 13:40 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/22 "2024-11-02T13:40:22Z")

</div>

Thanks I appreciate the flow, but I think there's some miscommunication in what I'm looking for help on.

I'm trying to figure out how to extract the JSON object data to begin with. The demo all has the sample data pre cut and pasted and that's not what I'm looking to do.

My programming knowledge is when I was a kid I (vaguely) learned BASIC (yeah, '70s BASIC) so in my head, I could see it as a for/next loop, like (and seriously, I can remember basically zero coding so this will NOT be proper code at all but will hopefully give you the gist of what I'm hoping to achieve):  
`for x=1-7`  
`let msg.payload.timelines.minutely[x].values.temperature = math.round(msg.payload.temp.x)`  
`next x`

And then have that output as 7 separate messages.

Does that clarify what I'm trying to achieve?

---

<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:** [2 November 2024 13:47 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/23 "2024-11-02T13:47:21Z")

</div>

> [@mobamoba](#):
>
> Thanks I appreciate the flow, but I think there's some miscommunication in what I'm looking for help on.

Honestly, I kinda knew that would be the case.

> **I did ask 4 times**
>
> > [@Steve-Mcl](#):
> >
> > include a sample of how you expect the array to look after processing each element
> 
> > [@Steve-Mcl](#):
> >
> > include a sample of how you expect the array to look after processing each element
> 
> > [@Steve-Mcl](#):
> >
> > include a sample of how you expect the array to look after processing each element
> 
> > [@Steve-Mcl](#):
> >
> > and explaining how you want the final 60 values to be presented?
> > 
> > Perhaps a different question will help you help me to help you!
> > 
> > What will you use these 60 values for? Display in a table on a dashboard? display in 60 dashboard gauges or 60 separate text fields? Passing them to MQTT as on array? Passing them to MQTT as 60 unique topic+value pairs? putting them in to a database? ???
> > 
> > It matters because any solution I give you has about a 95% chance of NOT actually being what you need - then i will have wasted even more of my time!

And lets not forget, V2 in my demo does what you asked:

> [@Steve-Mcl](#):
>
> > [@mobamoba](#):
> >
> > I just want 60 separate temperatures as 60 separate payloads.
> 
> ok, good, that is the first time you have said that. That helps.

  

but lets not dwell - i am hopeful you now realise why the questions were important to avoid confusion. Lets get your issue resolved...

  

> [@mobamoba](#):
>
> I'm trying to figure out how to extract the JSON object data to begin with.

That is not clear Im afraid. What _exactly_ is it you want to output?

can you provide a sample of what the final output will look like.

e.g.

- do you want 60 separate objects in 60 separate messages?
- do you simply want to move the data from `msg.payload.timelines.minutely` to `msg.payload` so that you can access ALL of the OBJECT via `msg.payoad[x]` ?
- Do you just want the data left where it is but do a math round on all of the temperature values?

Hopefully since we have given you a couple of demos (that as predicted were not what you wanted) - perhaps you can help us to help you?

---

<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:** [2 November 2024 13:56 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/24 "2024-11-02T13:56:44Z")

</div>

I 'd `msg.payload.timelines.minutely[x].values.temperature` - which is a number - to become x separate payloads. So if:  
`msg.payload.timelines.minutely[1].values.temperature` is number 52  
`msg.payload.timelines.minutely[2].values.temperature` is number 58  
`msg.payload.timelines.minutely[3].values.temperature` is number 55  
etc. etc. through all the values in the array  
then I want, as output, x messages:  
`msg.payload.1` = 52  
`msg.payload.2` = 58  
`msg.payload.3` = 55

Is that clearer?

---

<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:** [2 November 2024 14:03 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/25 "2024-11-02T14:03:20Z")

</div>

> [@mobamoba](#):
>
> `msg.payload.1` = 52  
> `msg.payload.2` = 58  
> `msg.payload.3` = 55
> 
> Is that clearer?

Perfect (though I would strongly not recommend that since using numbers as property names is not good practice)

and, in essence, V1 of the demo pretty much does that but with array syntax e.g. `msg.payload[1]` is the temperature of `msg.payload.timelines.minutely[1].values.temperature`, `msg.payload.timelines.minutely[2].values.temperature` is in `msg.payload[2]` is that not good enough?

If you give me 5 mins, I can provide the non-recommended output you asked for!

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 November 2024 14:06 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/26 "2024-11-02T14:06:28Z")

</div>

> [@mobamoba](#):
>
> I want, as output, x messages:  
> `msg.payload.1` = 52  
> `msg.payload.2` = 58  
> `msg.payload.3` = 55

You really want an element "1" in your first message with the value 52, an element "2" in your second message with value 58, etc?

Or do you want your message1 to contain just 52, message2 to contain 58 etc?

How will you be using these values further along the flow?

---

<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:** [2 November 2024 14:09 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/27 "2024-11-02T14:09:38Z")

</div>

> [@mobamoba](#):
>
> I want, as output, x messages:  
> `msg.payload.1` = 52  
> `msg.payload.2` = 58  
> `msg.payload.3` = 55

Here you go...

![chrome_rrsA9TRPPD](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/4769fb8a69ee1ec6e56fc5b7e366cf0e2bf7c4f3.gif)

```auto
[{"id":"d66888a262efc6d6","type":"comment","z":"2290795c114cdec3","name":"V4: same as V1 but converts the array to an object with numbered properties","info":"","x":540,"y":660,"wires":[]},{"id":"fa6d0402d2f3ede5","type":"inject","z":"2290795c114cdec3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":700,"wires":[["22793515a532fd28"]]},{"id":"22793515a532fd28","type":"template","z":"2290795c114cdec3","name":"sample data","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n \"timelines\": {\n \"minutely\": [\n {\n \"time\": \"2024-11-02T12:15:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0,\n \"dewPoint\": 35.26,\n \"freezingRainIntensity\": 0,\n \"humidity\": 58,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 49.66,\n \"temperatureApparent\": 49.66,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 19.85,\n \"windSpeed\": 6.99\n }\n },\n {\n \"time\": \"2024-11-02T12:16:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.04,\n \"dewPoint\": 35.29,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.93,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 49.73,\n \"temperatureApparent\": 49.73,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 19.89,\n \"windSpeed\": 7.04\n }\n },\n {\n \"time\": \"2024-11-02T12:17:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.09,\n \"dewPoint\": 35.32,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.85,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 49.8,\n \"temperatureApparent\": 49.8,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 19.92,\n \"windSpeed\": 7.09\n }\n },\n {\n \"time\": \"2024-11-02T12:18:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.13,\n \"dewPoint\": 35.35,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.78,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 49.87,\n \"temperatureApparent\": 49.87,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 19.95,\n \"windSpeed\": 7.13\n }\n },\n {\n \"time\": \"2024-11-02T12:19:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.17,\n \"dewPoint\": 35.37,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.7,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 49.93,\n \"temperatureApparent\": 49.93,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 19.99,\n \"windSpeed\": 7.18\n }\n },\n {\n \"time\": \"2024-11-02T12:20:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.21,\n \"dewPoint\": 35.4,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.63,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50,\n \"temperatureApparent\": 50,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.02,\n \"windSpeed\": 7.23\n }\n },\n {\n \"time\": \"2024-11-02T12:21:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.26,\n \"dewPoint\": 35.43,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.56,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.07,\n \"temperatureApparent\": 50.07,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.06,\n \"windSpeed\": 7.28\n }\n },\n {\n \"time\": \"2024-11-02T12:22:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.3,\n \"dewPoint\": 35.45,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.48,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.14,\n \"temperatureApparent\": 50.14,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.09,\n \"windSpeed\": 7.32\n }\n },\n {\n \"time\": \"2024-11-02T12:23:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.34,\n \"dewPoint\": 35.48,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.41,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.2,\n \"temperatureApparent\": 50.2,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.12,\n \"windSpeed\": 7.37\n }\n },\n {\n \"time\": \"2024-11-02T12:24:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.38,\n \"dewPoint\": 35.51,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.33,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.27,\n \"temperatureApparent\": 50.27,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.16,\n \"windSpeed\": 7.42\n }\n },\n {\n \"time\": \"2024-11-02T12:25:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.43,\n \"dewPoint\": 35.54,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.26,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.34,\n \"temperatureApparent\": 50.34,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.19,\n \"windSpeed\": 7.47\n }\n },\n {\n \"time\": \"2024-11-02T12:26:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.47,\n \"dewPoint\": 35.56,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.19,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.41,\n \"temperatureApparent\": 50.41,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.23,\n \"windSpeed\": 7.51\n }\n },\n {\n \"time\": \"2024-11-02T12:27:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.51,\n \"dewPoint\": 35.59,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.11,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.47,\n \"temperatureApparent\": 50.47,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.26,\n \"windSpeed\": 7.56\n }\n },\n {\n \"time\": \"2024-11-02T12:28:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.55,\n \"dewPoint\": 35.62,\n \"freezingRainIntensity\": 0,\n \"humidity\": 57.04,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.21,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.54,\n \"temperatureApparent\": 50.54,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.29,\n \"windSpeed\": 7.61\n }\n },\n {\n \"time\": \"2024-11-02T12:29:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.6,\n \"dewPoint\": 35.65,\n \"freezingRainIntensity\": 0,\n \"humidity\": 56.96,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.2,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.61,\n \"temperatureApparent\": 50.61,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.33,\n \"windSpeed\": 7.66\n }\n },\n {\n \"time\": \"2024-11-02T12:30:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.64,\n \"dewPoint\": 35.67,\n \"freezingRainIntensity\": 0,\n \"humidity\": 56.89,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.2,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.68,\n \"temperatureApparent\": 50.68,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.36,\n \"windSpeed\": 7.7\n }\n },\n {\n \"time\": \"2024-11-02T12:31:00Z\",\n \"values\": {\n \"cloudBase\": null,\n \"cloudCeiling\": null,\n \"cloudCover\": 0.68,\n \"dewPoint\": 35.7,\n \"freezingRainIntensity\": 0,\n \"humidity\": 56.82,\n \"precipitationProbability\": 0,\n \"pressureSurfaceLevel\": 30.2,\n \"rainIntensity\": 0,\n \"sleetIntensity\": 0,\n \"snowIntensity\": 0,\n \"temperature\": 50.74,\n \"temperatureApparent\": 50.74,\n \"uvHealthConcern\": 0,\n \"uvIndex\": 0,\n \"visibility\": 9.94,\n \"weatherCode\": 1000,\n \"windDirection\": 333.88,\n \"windGust\": 20.4,\n \"windSpeed\": 7.75\n }\n }\n]\n }\n}","output":"json","x":480,"y":700,"wires":[["9a8084576d726a90"]]},{"id":"250544b3ed33c940","type":"split","z":"2290795c114cdec3","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":500,"y":760,"wires":[["4a2dc9db83aea183"]]},{"id":"9a8084576d726a90","type":"change","z":"2290795c114cdec3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.timelines.minutely","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":760,"wires":[["250544b3ed33c940"]]},{"id":"47b37ec837007416","type":"debug","z":"2290795c114cdec3","name":"full array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":820,"wires":[]},{"id":"4a2dc9db83aea183","type":"change","z":"2290795c114cdec3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.values.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":760,"wires":[["33a135ea8c88f579"]]},{"id":"33a135ea8c88f579","type":"join","z":"2290795c114cdec3","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":"false","timeout":"","count":"","reduceRight":false,"x":860,"y":760,"wires":[["b4f7426eebcbaea3"]]},{"id":"b4f7426eebcbaea3","type":"function","z":"2290795c114cdec3","name":"convert to number prop object","func":"const obj = {}\nfor (let index = 0; index < msg.payload.length; index++) {\n obj[index] = msg.payload[index];\n}\nmsg.payload = obj\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":820,"wires":[["47b37ec837007416"]]}]

```

---

<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:** [2 November 2024 14:10 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/28 "2024-11-02T14:10:28Z")

</div>

> [@jbudd](#):
>
> Or do you want your message1 to contain just 52, message2 to contain 58 etc?

That is exactly what V2 of my demo does 🤷

---

<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:** [2 November 2024 14:12 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/29 "2024-11-02T14:12:40Z")

</div>

What I didn't understand about the demo flows you provided is that it was all inject nodes whereas I'm getting the data, in JSON form, from a website, so the input is that data, the JSON object data direct from the website.

So with that as my input, I'm trying to get `msg.payload.timelines.minutely[x].values.temperature` to output 60 separate messages by iterating x from 1-60.

I can, of course, simply stick 60 Change nodes on the HTTP output and individually have each Change node create a msg.payload - `msg.payload.timelines.minutely[1].values.temperature` , `msg.payload.timelines.minutely[2].values.temperature` etc. But 60 Change will be a visual nightmare! So I'm looking for a way to have that same outcome but without having the tedium of having to setup 60 Change nodes.

---

<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:** [2 November 2024 14:17 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/30 "2024-11-02T14:17:09Z")

</div>

I dont have access to your API data and you did not provide details of how to access it - so I had to do something. It is very common to simulate the final outcome using injects. It is simply a matter of learning how it works and replacing the demo data/inject with your real data. e.g.

![chrome_X9C90T6ntV](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea2a387d2c6667f1f302bec9bef2368e7bd8c7b6.gif)

---

<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:** [2 November 2024 14:21 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/31 "2024-11-02T14:21:36Z")

</div>

> [@mobamoba](#):
>
> `msg.payload.timelines.minutely[x].values.temperature` to output 60 separate messages by iterating x from 1-60.

You do realise that is EXACTLY what V2 does?

---

<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:** [2 November 2024 14:23 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/32 "2024-11-02T14:23:07Z")

</div>

> [@mobamoba](#):
>
> What I didn't understand about the demo flows you provided is that it was all inject nodes whereas I'm getting the data, in JSON form, from a website, so the input is that data, the JSON object data direct from the website.

Makes no differnecne, these are examples and we do not have your http request node or api key. Replace the injects with http request nodes, or what ever node you are using

> [@mobamoba](#):
>
> So with that as my input, I'm trying to get `msg.payload.timelines.minutely[x].values.temperature` to output 60 separate messages by iterating x from 1-60.

Both Steve and myself have given you example flows that do this. You can identify each message using msg.parts.index, as the split node adds this to each of the 60 outputs. Use the debug node set to complete message object to see all the message properties.

You may benefit from watching the [essentials videos](https://m.youtube.com/watch?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&v=ksGeUD26Mw0&embeds_referring_euri=https%3A%2F%2Fnodered.org%2F&source_ve_path=OTY3MTQ&feature=emb_imp_woyt)

---

<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:** [2 November 2024 14:26 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/33 "2024-11-02T14:26:23Z")

</div>

You're saying I can replace the Inject and Sample Data node in V2 with the HTTP data? Okay I didn't understand that. Thanks

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 November 2024 14:28 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/34 "2024-11-02T14:28:10Z")

</div>

> [@mobamoba](#):
>
> But 60 Change will be a visual nightmare! So I'm looking for a way to have that same outcome but without having the tedium of having to setup 60 Change nodes.

The split node will, as the name hints, split your complex message into multiple individual messages.

I think that you need to tell it to split `msg.payload.timelines.minutely`  
Which should give you 60 messages each containing (for example)  
payload.values.temperature and a lot of other stuff.

Now wire that node to a change node in which you move msg.payload.values.temperature to msg.payload.

A debug node after that should show you 60 messages: 52, 58, 55 etc

Steve has explained things and asked lots of questions to clarify what you need. Instead of answering, you have basically repeated your original question. It makes it hard to help you

---

<div class="post-metadata">

**Author:** ![berijan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/berijan/32/35313_2.png) [@berijan](https://discourse.nodered.org/u/berijan)\
**Post date:** [8 November 2024 13:36 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/35 "2024-11-08T13:36:14Z")

</div>

One way is to use a function node, see my example

```auto
[
    {
        "id": "5016199e25cc9c6d",
        "type": "inject",
        "z": "c9923f644696b474",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 160,
        "wires": [
            [
                "3832a661619a3c78"
            ]
        ]
    },
    {
        "id": "3832a661619a3c78",
        "type": "function",
        "z": "c9923f644696b474",
        "name": "simulate indata",
        "func": "let newMsg = {payload : {timelines : {minutely : []}}}; ;\n\n\nlet objMinutely = [];\n\nfor (let index = 0; index < 60; index++) {\n \n let values = {temperature : Math.random() * 100.0};\n\n newMsg.payload.timelines.minutely.push(values);\n \n}\n\n\nreturn newMsg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 160,
        "wires": [
            [
                "57fb04d05b598776",
                "1eb647eed7e7231f"
            ]
        ]
    },
    {
        "id": "57fb04d05b598776",
        "type": "debug",
        "z": "c9923f644696b474",
        "name": "debug 9",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 160,
        "wires": []
    },
    {
        "id": "1eb647eed7e7231f",
        "type": "function",
        "z": "c9923f644696b474",
        "name": "ArraySplit",
        "func": "\nlet outMessages = [];\n\nfor (let index = 0; index < msg.payload.timelines.minutely.length; index++) {\n\n outMessages.push({payload : msg.payload.timelines.minutely[index].temperature});\n \n }\n\nreturn [outMessages];",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 260,
        "wires": [
            [
                "290e862a1ebcccc3"
            ]
        ]
    },
    {
        "id": "290e862a1ebcccc3",
        "type": "debug",
        "z": "c9923f644696b474",
        "name": "debug 10",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 260,
        "wires": []
    }
]

```

---

<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:** [6 February 2025 13:36 UTC](https://discourse.nodered.org/t/split-json-object-array/92865/36 "2025-02-06T13:36:23Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/split-json-object-array/92865.md?page=1)
