Split JSON Object Array

The following is part of an output from a weather API and I'm trying to figure out how to split it.

payload.timelines.minutely[0].values.temperature

The [0] is just one of the array - it goes from [0] to [60] and I'm sure there some simple node or function that will replace the number - [0] - with a variable - [ x ] - and iterate the output of all the data from 0-60, but I can't figure out how to do that or what the formatting should be for the [ ] part to make Split node work (or a function of some kind).

Thanks.

You could simply move payload.timelines.minutely into payload, pass it through split, make any changes you need using a change or function, then back into a join node to reassemble the array.

change > split > change > join

Sorry I don't understand that.

  1. move payload.timelines.minutely into payload

  2. pass it through split node

  3. make any changes you need using a change or function

  4. back into a join node to reassemble the array.

Better?

Did you try?

Sorry, I'm not a programmer so I honestly don't understand. What I'm trying to achieve in the end is to take payload.timelines.minutely[x].values.temperature and extract the payload for:

payload.timelines.minutely[0].values.temperature
payload.timelines.minutely[1].values.temperature
payload.timelines.minutely[2].values.temperature
payload.timelines.minutely[3].values.temperature

etc.

Extract it - to what?

what is the shape of the final data?

do you want an array of 60 numbers?

do you want an object with 60 properties?

do you want 60 individual messages each with their own unique topic?

Do you know what the split node does? Perhaps you should have some play time:
https://cookbook.nodered.org/basic/operate-on-array



If you want further help, provide some

  1. real sample data by clicking the copy value
  2. paste it into a code block
  3. include a sample of how you expect the array to look after processing each element


how to grab data so we can re-use it and help you

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

I know what a split node is. I can't figure out the formatting. I don't know what do with the [] part.
When I put msg.payload.timelines.minutely[].values.temperature in the split node, it errors so obviously I'm doing something wrong with that [] part but I don't know how to tell it to output each "values.temperature" for however many are in th [] part of the array.

I never said put msg.payload.timelines.minutely[].values.temperature in the split node. That would be invalid!

As I said before:

The value is a number - it's a temperature. The data gives the temperature for each minute over 60 minutes, thus I have 60 msg.payload.timelines.minutely[0-60].values.temperature objects (msg.payload.timelines.minutely[0].values.temperature`, msg.payload.timelines.minutely[1].values.temperature`
etc with 60 different temperature values. I want to extract all 60 values without have to do 60 change nodes.

Yes, and i will happily show you how, just as soon as you answer...

I'm not about to create some fake data that might not match what you have, then generate some output in a format that might not be what you want!!!

The value of
payload.timelines.minutely[0].values.temperature is number: 59.52.
At the end I just want that number but I want I want it for all 60 in the array.

Yes, and how do you want that data. In an array? as properties of an object? as individual messages?

Seriously, do you not want help?

I am willing to write the flow for you but you can't do a simple task of providing real sample data 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!

I've given you literally all the data that's there. I just want 60 separate temperatures as 60 separate payloads. After that, I know how to work with them. I can't figure out how to split them out programmatically.

ok, good, that is the first time you have said that. That helps.

Now can you provide some real sample data as requested?

no, you have given me an object path. I cannot use that to build a demo flow for you. I need real sample data to avoid wasting time.

Steve is asking for the input data
e.g
something like this


    "timelines": {
        "minutely": [
            {
                "values": {
                    "temperature": 10
                }
            },
            {
                "values": {
                    "temperature": 20
                }
            }
        ]
    }
}

He would then create an example flow like this

[{"id":"0ce8c84eecaf538f","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"timelines\":{\"minutely\":[{\"values\":{\"temperature\":10}},{\"values\":{\"temperature\":20}}]}}","payloadType":"json","x":910,"y":7740,"wires":[["9a8b5b275aa9a832"]]},{"id":"9a8b5b275aa9a832","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload.timelines.minutely","x":1090,"y":7740,"wires":[["ac596fc96fb81c1c"]]},{"id":"ac596fc96fb81c1c","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.timelines.minutely.values.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":7740,"wires":[["608aec15e14e094c"]]},{"id":"608aec15e14e094c","type":"debug","z":"d1395164b4eec73e","name":"debug 2577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1470,"y":7740,"wires":[]}]

which would set out how to configure the split and move payloads etc

How to import/export a flow

There's a top-level thing I'm not understanding. I know how to extract the final value I want on an individual basis, like I know how to get the value for payload.timelines.minutely[0].values.temperature. I know how to enter that and pull the temperature value and make use of it elsewhere in my flow.

What I don't know and what I can't find anywhere in the documentation probably because it's something people who program inherently understand but which I don't is, when the data from an HTTP call comes in the form of msg.object.object.array[number] and when you expand that it says [0...9] and when you expand that, there's objects 0-9 and when you expand that you get you get a list of the final values, like how do you get from msg.object.object.array[].object.value without having to do:
msg.object.object.array[0].object.value
msg.object.object.array[1].object.value
msg.object.object.array[2].object.value

I know how to do that. What I don't know how to do is put a variable in the [] rather than a particular number and get separate payloads for each, like msg.payload.value0, msg.payload.value1, msg.payload.value2, etc.

So just at a top-level, I don't understand how that works.

I can demonstrate several solutions, but until you provide sample data, i cannot.

Can you please just grab some sample input data by clicking the copy value button on the payload as I have asked and shown 3 times.

here it is one more time for good measure:

{"timelines":{"minutely":[{"time":"2024-11-02T12:15:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0,"dewPoint":35.26,"freezingRainIntensity":0,"humidity":58,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":49.66,"temperatureApparent":49.66,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":19.85,"windSpeed":6.99}},{"time":"2024-11-02T12:16:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.04,"dewPoint":35.29,"freezingRainIntensity":0,"humidity":57.93,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":49.73,"temperatureApparent":49.73,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":19.89,"windSpeed":7.04}},{"time":"2024-11-02T12:17:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.09,"dewPoint":35.32,"freezingRainIntensity":0,"humidity":57.85,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":49.8,"temperatureApparent":49.8,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":19.92,"windSpeed":7.09}},{"time":"2024-11-02T12:18:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.13,"dewPoint":35.35,"freezingRainIntensity":0,"humidity":57.78,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":49.87,"temperatureApparent":49.87,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":19.95,"windSpeed":7.13}},{"time":"2024-11-02T12:19:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.17,"dewPoint":35.37,"freezingRainIntensity":0,"humidity":57.7,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":49.93,"temperatureApparent":49.93,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":19.99,"windSpeed":7.18}},{"time":"2024-11-02T12:20:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.21,"dewPoint":35.4,"freezingRainIntensity":0,"humidity":57.63,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50,"temperatureApparent":50,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.02,"windSpeed":7.23}},{"time":"2024-11-02T12:21:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.26,"dewPoint":35.43,"freezingRainIntensity":0,"humidity":57.56,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.07,"temperatureApparent":50.07,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.06,"windSpeed":7.28}},{"time":"2024-11-02T12:22:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.3,"dewPoint":35.45,"freezingRainIntensity":0,"humidity":57.48,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.14,"temperatureApparent":50.14,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.09,"windSpeed":7.32}},{"time":"2024-11-02T12:23:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.34,"dewPoint":35.48,"freezingRainIntensity":0,"humidity":57.41,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.2,"temperatureApparent":50.2,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.12,"windSpeed":7.37}},{"time":"2024-11-02T12:24:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.38,"dewPoint":35.51,"freezingRainIntensity":0,"humidity":57.33,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.27,"temperatureApparent":50.27,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.16,"windSpeed":7.42}},{"time":"2024-11-02T12:25:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.43,"dewPoint":35.54,"freezingRainIntensity":0,"humidity":57.26,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.34,"temperatureApparent":50.34,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.19,"windSpeed":7.47}},{"time":"2024-11-02T12:26:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.47,"dewPoint":35.56,"freezingRainIntensity":0,"humidity":57.19,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.41,"temperatureApparent":50.41,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.23,"windSpeed":7.51}},{"time":"2024-11-02T12:27:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.51,"dewPoint":35.59,"freezingRainIntensity":0,"humidity":57.11,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.47,"temperatureApparent":50.47,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.26,"windSpeed":7.56}},{"time":"2024-11-02T12:28:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.55,"dewPoint":35.62,"freezingRainIntensity":0,"humidity":57.04,"precipitationProbability":0,"pressureSurfaceLevel":30.21,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.54,"temperatureApparent":50.54,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.29,"windSpeed":7.61}},{"time":"2024-11-02T12:29:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.6,"dewPoint":35.65,"freezingRainIntensity":0,"humidity":56.96,"precipitationProbability":0,"pressureSurfaceLevel":30.2,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.61,"temperatureApparent":50.61,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.33,"windSpeed":7.66}},{"time":"2024-11-02T12:30:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.64,"dewPoint":35.67,"freezingRainIntensity":0,"humidity":56.89,"precipitationProbability":0,"pressureSurfaceLevel":30.2,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.68,"temperatureApparent":50.68,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.36,"windSpeed":7.7}},{"time":"2024-11-02T12:31:00Z","values":{"cloudBase":null,"cloudCeiling":null,"cloudCover":0.68,"dewPoint":35.7,"freezingRainIntensity":0,"humidity":56.82,"precipitationProbability":0,"pressureSurfaceLevel":30.2,"rainIntensity":0,"sleetIntensity":0,"snowIntensity":0,"temperature":50.74,"temperatureApparent":50.74,"uvHealthConcern":0,"uvIndex":0,"visibility":9.94,"weatherCode":1000,"windDirection":333.88,"windGust":20.4,"windSpeed":7.75}}

Something like this if i understand correctly

[{"id":"0ce8c84eecaf538f","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"timelines\":{\"minutely\":[{\"values\":{\"temperature\":10}},{\"values\":{\"temperature\":20}}]}}","payloadType":"json","x":910,"y":7740,"wires":[["ac596fc96fb81c1c"]]},{"id":"ac596fc96fb81c1c","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.timelines.minutely[msg.topic].values.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":7740,"wires":[["608aec15e14e094c"]]},{"id":"608aec15e14e094c","type":"debug","z":"d1395164b4eec73e","name":"debug 2577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1470,"y":7740,"wires":[]}]