# Searching values in an object

**URL:** <https://discourse.nodered.org/t/searching-values-in-an-object/94537>\
**Category:** Dashboard\
**Tags:** node-red-dashboard, dashboard-2\
**Created:** [11 January 2025 20:38 UTC](https://discourse.nodered.org/t/searching-values-in-an-object/94537 "2025-01-11T20:38:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmessers](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tmessers](https://discourse.nodered.org/u/tmessers)\
**Post date:** [11 January 2025 20:38 UTC](https://discourse.nodered.org/t/searching-values-in-an-object/94537/1 "2025-01-11T20:38:45Z")

</div>

Hi folks,  
i am looking for help. Maybe one can help me.  
I am requesting data from a public api.  
i read out data on an daily basis and want to plot it in a dashboard 2.0 chart in node-red.  
The returned data is a json object as you see below.  
so far i didn't find the solution to get this working.

Does anyone have an idea?

Thanks for your help

```auto
{"jsonData":{"request":{"component":"1","scope":"2","station":"286","date_from":"2025-01-11","date_to":"2025-01-11","time_from":"01:00:00","time_to":"24:00:00","index":"id","lang":"en","datetime_from":"2025-01-11 00:00:00","datetime_to":"2025-01-11 23:00:00"},"indices":{"data":{"station id":{"date start":["0: Id of component - integer","1: Id of scope - integer","2: Value - number","3: Date of measure end - string","4: Index - string|null"]}}},"data":{"286":{"2025-01-11 00:00:00":[1,2,5,"2025-01-11 01:00:00",null],"2025-01-11 01:00:00":[1,2,5,"2025-01-11 02:00:00",null],"2025-01-11 02:00:00":[1,2,8,"2025-01-11 03:00:00",null],"2025-01-11 03:00:00":[1,2,8,"2025-01-11 04:00:00",null],"2025-01-11 04:00:00":[1,2,7,"2025-01-11 05:00:00",null],"2025-01-11 05:00:00":[1,2,5,"2025-01-11 06:00:00",null],"2025-01-11 06:00:00":[1,2,6,"2025-01-11 07:00:00",null],"2025-01-11 07:00:00":[1,2,7,"2025-01-11 08:00:00",null],"2025-01-11 08:00:00":[1,2,9,"2025-01-11 09:00:00",null],"2025-01-11 09:00:00":[1,2,7,"2025-01-11 10:00:00",null],"2025-01-11 10:00:00":[1,2,9,"2025-01-11 11:00:00",null],"2025-01-11 11:00:00":[1,2,10,"2025-01-11 12:00:00",null],"2025-01-11 12:00:00":[1,2,16,"2025-01-11 13:00:00",null],"2025-01-11 13:00:00":[1,2,17,"2025-01-11 14:00:00",null],"2025-01-11 14:00:00":[1,2,15,"2025-01-11 15:00:00",null],"2025-01-11 15:00:00":[1,2,16,"2025-01-11 16:00:00",null],"2025-01-11 16:00:00":[1,2,18,"2025-01-11 17:00:00",null],"2025-01-11 17:00:00":[1,2,17,"2025-01-11 18:00:00",null],"2025-01-11 18:00:00":[1,2,16,"2025-01-11 19:00:00",null],"2025-01-11 19:00:00":[1,2,17,"2025-01-11 20:00:00",null]}}}}

```

I created a code to read out the data in need to go on

```auto
var inputData = msg.payload;
var result = [];

const stationData = inputData ["jsonData"]["data"]["286"];

for (const dateStart in stationData) {
  const value = stationData[dateStart][2]; // Index 2 enthält den Value
  result.push({ x: dateStart, y: value });
}

var msg = {
  payload: result
};

return msg;

```

Using this code i get the object

```auto
[{"x":"2025-01-12 00:00:00","y":27},{"x":"2025-01-12 01:00:00","y":19},{"x":"2025-01-12 02:00:00","y":14},{"x":"2025-01-12 03:00:00","y":10},{"x":"2025-01-12 04:00:00","y":10},{"x":"2025-01-12 05:00:00","y":11},{"x":"2025-01-12 06:00:00","y":10},{"x":"2025-01-12 07:00:00","y":8},{"x":"2025-01-12 08:00:00","y":9}]

```

Putting this in the dashbnorad 2.0 chart node doesnt plot the graph.  
I adjusted the chart node as follows:  
Series : None  
Y Key: y  
X: Key: x

I do not have a clue what i am doing wrong.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 January 2025 10:05 UTC](https://discourse.nodered.org/t/searching-values-in-an-object/94537/2 "2025-01-12T10:05:50Z")

</div>

The timestamp can (apparently) not be parsed by the chart node.

If you change the function to something like:

```auto

const input = msg.payload.jsonData.data['286']
msg.payload = Object.values(input).map(d=>{return {x:new Date(d[3]),y:d[2]}})
return msg;

```

It will return dates that it can parse:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/06dfaedc88338a61384c9368c51d25ee1ad7fc92.png)

Not entirely sure if this will be 100% correct, or that the chart node requires an actual timestamp, perhaps this should be clarified in the documentation, ie 'what is a timestamp' or valid timeformat for the input @joepavitt ?

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [12 January 2025 10:24 UTC](https://discourse.nodered.org/t/searching-values-in-an-object/94537/3 "2025-01-12T10:24:26Z")

</div>

Yeah, we should in theory support the string as it is a valid timestamp - can you raise an issue please?

We should be able to check if the value is already a `Date` object, and if not, and the chart is set to be a "Timeseries" x-axis, then we just try to parse whatever we're given

---

<div class="post-metadata">

**Author:** ![tmessers](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tmessers](https://discourse.nodered.org/u/tmessers)\
**Post date:** [15 January 2025 15:00 UTC](https://discourse.nodered.org/t/searching-values-in-an-object/94537/4 "2025-01-15T15:00:30Z")

</div>

Thanks you for your reply. It works well.

---

<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:** [29 January 2025 15:00 UTC](https://discourse.nodered.org/t/searching-values-in-an-object/94537/5 "2025-01-29T15:00:31Z")

</div>

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