# Convert msg.object to a new msg.object (function)

**URL:** <https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141>\
**Category:** General\
**Created:** [12 June 2019 17:50 UTC](https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141 "2019-06-12T17:50:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![E\_T](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@E\_T](https://discourse.nodered.org/u/E_T)\
**Post date:** [12 June 2019 17:50 UTC](https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141/1 "2019-06-12T17:50:31Z")

</div>

Hallo,

i need an msg-object for the World-Map like this: {"name":"Test", "lat":52.31, "lon":7.05}

i got an msg-object like this:

 ![payload](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/25ce38384f529833ad768d310b482bfce951193e.jpeg)

My idea

var payload=msg.payload;

var newMsg = {"name":"Test", "lat":52.31, "lon":7.05}  
newMsg.lat = payload.payload\_fields.location.latitude;  
newMsg.lon = payload.payload\_fields.location.longitude;

return newMsg;

Can someone help?

Greetings

Ernst

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [12 June 2019 18:20 UTC](https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141/2 "2019-06-12T18:20:41Z")

</div>

Document says:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c842a48ceb96081ebc8cd3380830e5c7cf90d40e.png)

You'll need to think again and reprase the sentence: _i need an msg-object for the World-Map like this: {"name":"Test", "lat":52.31, "lon":7.05}_

As you see, the **payload** property of the `msg` object must be filled with `name`, `lon` and `lat` properties (and their values of course)

---

<div class="post-metadata">

**Author:** ![E\_T](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@E\_T](https://discourse.nodered.org/u/E_T)\
**Post date:** [12 June 2019 18:41 UTC](https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141/3 "2019-06-12T18:41:17Z")

</div>

I think this works:

var payload=msg.payload;

var newMsg = {payload:{ "name":"Test", "lat":52.31, "lon":7.05}}

newMsg.payload.lat = payload.payload\_fields.location.latitude;

newMsg.payload.lon = payload.payload\_fields.location.longitude;

return newMsg;

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 June 2019 04:12 UTC](https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141/4 "2019-06-13T04:12:43Z")

</div>

You could shrink that slightly - but yes you have the right idea 🙂

```
var newMsg = {payload:{ "name":"Test"}}
newMsg.payload.lat = msg,payload.payload_fields.location.latitude;
newMsg.payload.lon = msg.payload.payload_fields.location.longitude;
return newMsg;
```

---

<div class="post-metadata">

**Author:** ![E\_T](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@E\_T](https://discourse.nodered.org/u/E_T)\
**Post date:** [14 June 2019 04:52 UTC](https://discourse.nodered.org/t/convert-msg-object-to-a-new-msg-object-function/12141/5 "2019-06-14T04:52:12Z")

</div>

Thank you!
