Extract value on changing date


Hello,

i need to extract the tho date from the json object. The date's always change depending what day it is.
The data in picture is from the last date's, 2022-01-03 and 2022-01-04.

Welcome to the forum @Stevom

For the record that is not a JSON object (JSON is a string representation of an object). That is a javascript object.

Given the data you show, exactly what to you want to get out of it?

Hi,
i want to extract the two values from the two date's under watt_hours_day.
image
This is some data for today and tomorrow.

Do you know what dates you expect in the message? If so there is a great page in the docs that will explain how to use the debug panel to find the right path to 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

https://nodered.org/docs/user-guide/messages

If you don't know what dates there are then you can use javascript in a function. In particular look at Object.keys(). You can use something like
let keys = msg.payload.watt_hours_day
which will give you an array of the date strings.

Hi ,

Thanks for the help.

The two dates are always the date for today and tomorrow.

Here is an example using A change node, you could also do it using a function node, You do not say how you want the data presented.

[{"id":"d09c6bd0.6d9d9","type":"inject","z":"1378ba83.90c825","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"watt_hour_days\":{\"2021-01-04\":1234,\"2021-01-05\":5678}}","payloadType":"json","x":200,"y":340,"wires":[["b515b3a4.437d18"]]},{"id":"b515b3a4.437d18","type":"change","z":"1378ba83.90c825","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$keys($$.payload.watt_hour_days).{\"date\": $, \"value\" :$lookup($$.payload.watt_hour_days, $)}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":340,"wires":[["ee01ad6c.ac18b"]]},{"id":"ee01ad6c.ac18b","type":"debug","z":"1378ba83.90c825","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":340,"wires":[]}]

expression

$keys($$.payload.watt_hour_days).{
   "date": $,
   "value" :$lookup($$.payload.watt_hour_days, $)
}

Hi E1cid,

thanks look great.

But if i try it in my flow. I get an error.

When i debug the http request it is ok. Butt when i put the change node in, i get the error.

When you posted your question you failed to posted any usable data(image can not be copied). I therefore created my own for the example. If you look at the property names they are not the same. Edit the expression and add your property names.
eg. $$.payload.result.watt_hours_day

Thank you very much.

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