How to create a msg with multi parameters

Hi: I want to creat a new msg in function node like the msg below with multi parameters. How I should write?
msg.payload : Object
object
weather: "Rain"
temp_maxc: 25.5
temp_minc: 18.3
humidity: 53
pressure: 1000

Like this?

msg.payload = {
 weather: "Rain",
 temp_maxc: 25.5,
 temp_minc: 18.3, 
 humidity: 53, 
 pressure: 1000
}
return msg;

To create an object in JS, its just {} this is quite fundamental - you would do yourself a favour to do a little online training.


EDIT...
Just released you said "new msg" (however I dont recommend creating new msg every time - my preference is to re-use the msg object.

If you REALLY need a new msg then...

var newMsg = {};// create a new object
newMsg.payload = {
 weather: "Rain",
 temp_maxc: 25.5,
 temp_minc: 18.3, 
 humidity: 53, 
 pressure: 1000
}
return newMsg;
1 Like

Thank u so much.
But it seems that I asked wrong...
The node "openweathermap" requires input msg.location.city and msg.location.country.
This is "location" rather than "payload". I know the "location" is not a correct parameter of msg.
How to create the msg like this..

Messages are regular JavaScript objects. They can have whatever properties you want them to have.

If you look at the code that @Steve-Mcl shared, he showed how to set msg.payload as an object of key/value pairs

So to set msg.location instead, you can do:

msg.location = {
   city: "here",
   country: "there"
}
1 Like