# How to simulate (inject) full message object

**URL:** https://discourse.nodered.org/t/how-to-simulate-inject-full-message-object/6048
**Category:** General
**Created:** [21 December 2018 21:05 UTC](https://discourse.nodered.org/t/how-to-simulate-inject-full-message-object/6048 "2018-12-21T21:05:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)
#### Post date: [21 December 2018 21:05 UTC](https://discourse.nodered.org/t/how-to-simulate-inject-full-message-object/6048/1 "2018-12-21T21:05:14Z")

</div>

Two parts to this question, one is a theoretical question, the other a practical question.

I have the Dark Sky node plugged into a function, which uses a for-loop to build an array, which I can then output to a dashboard graph. It shows percent chance of rain per hour, for next 24 hours.

**Function node:**

```
var m={};
m.series = ['% rain'];
m.labels = [];
m.data = [[]];
for (i=0;i<=24;i++) {
    m.labels.push(i);
    m.data[0].push(msg.data.hourly.data[i].precipProbability);
}

```

**Question 1 (practical)**  
As you can see, the X axis will display a count from 0 to 24. Instead I'd like it to display 4x labels, showing the hour of the day, e.g. 01:00, 07:00, 13:00, 19:00. These are provided in the incoming object:

```
msg.data.hourly.data[0].time
msg.data.hourly.data[6].time
msg.data.hourly.data[12].time
msg.data.hourly.data[18].time

```

I guess this question is in two parts: how to format the time, and how to display only 4 labels when there are 24 data points.

Re the first point, I have tried to push this into the m.labels array using .toTimeString(), i.e. `m.labels.push(msg.data.hourly.data[i].time.toTimeString());` but the graph still shows the long unix timestamp in the X axis label. (When I hover over the graph it says "invalid date format".) I also tried changing the X axis label in the graph node, but that didn't work. How can I achieve that?

**Question 2 (theoretical)**  
Let's say I don't want to keep using up the API limit of Dark Sky, every time I test my code, so instead I copy the entire message object output of the Dark Sky node into the clipboard (from the debug sidebar), then enter it into an inject node as JSON. After I clear the values in the graph, and unwire it from the Dark Sky node and re-wire it into my inject node... when I inject it, the graph doesn't display.

I _think_ this is because I've copied the whole message object into the inject node (JSON), and this includes e.g. even the topic. So I see why that wouldn't work.

But theoretically, how would I "simulate" the entire output of this Dark Sky node - or any other node for that matter?

(I say it's theoretical, because the API limit for Dark Sky is massive - I'm just curious)

Thanks

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [21 December 2018 22:23 UTC](https://discourse.nodered.org/t/how-to-simulate-inject-full-message-object/6048/2 "2018-12-21T22:23:49Z")

</div>

> [@hazymat](#):
>
> copy the entire message object output of the Dark Sky node into the clipboard (from the debug sidebar), then enter it into an inject node as JSON.

The issue is that the inject node will give you `msg.payload` = object

You are more likely to suceeed with this strategy if you paste the result of your copy in a function node, like this:

```auto
msg = {

paste your object
}

return msg;

```

---

<div class="post-metadata">

### Author: ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)
#### Post date: [22 December 2018 01:00 UTC](https://discourse.nodered.org/t/how-to-simulate-inject-full-message-object/6048/3 "2018-12-22T01:00:41Z")

</div>

Thanks @Andrei

For reference I was able to resolve my coding problem. I didn't understand that the unix timestamp stored in the array actually wasn't a date object, so had to create a new date object. Here's what I did for anyone wanting to do the same. In honesty, not sure why I had to multiply the value by 1000 but I saw this done elsewhere online and when I compared the dates, it worked.

```
var time = new Date(msg.data.hourly.data[i].time * 1000);
var hour = time.getHours();
var displayhour = hour + ":00h";

m.labels.push(displayhour);
m.data[0].push((msg.data.hourly.data[i].precipProbability)*100);
```
