# Change Payload include Array

**URL:** https://discourse.nodered.org/t/change-payload-include-array/1911
**Category:** General
**Created:** [30 July 2018 22:05 UTC](https://discourse.nodered.org/t/change-payload-include-array/1911 "2018-07-30T22:05:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kimou](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@kimou](https://discourse.nodered.org/u/kimou)
#### Post date: [30 July 2018 22:05 UTC](https://discourse.nodered.org/t/change-payload-include-array/1911/1 "2018-07-30T22:05:58Z")

</div>

My payload is like this  
{  
"deviceId":"B42EB8",  
"time":"2018-07-30T14:46:31.872257Z",  
"\_msgid":"bca8ce3a.2962b",  
"seq":"",  
"dataView":"",  
"enters":9866,  
"exits":11165,  
"type":"string",  
"unit":"",  
"recep":""  
"id":"",  
"MEE":"",  
"TWS":0,  
}

I would like with this format  
{  
"deviceId": "B42EB8",  
"time": "2018-07-30T14:46:31.872257Z",  
"seq": "",  
"dataView": [  
{  
"key": "enters",  
"value": 9866,  
"type": "string",  
"unit": "",  
},  
{  
"key": "exits",  
"value": 11165,  
"type": "string",  
"unit": "",  
}  
],  
"recep": [  
{  
"id": "",  
"MEE": 0,  
"TWS": 0  
}  
]  
}

Please, someone could help me

---

<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: [31 July 2018 00:15 UTC](https://discourse.nodered.org/t/change-payload-include-array/1911/2 "2018-07-31T00:15:47Z")

</div>

Below flow is not quite creative but it apparently does the job. Of course you will use only the second function node to transform your original object.

```auto
[{"id":"6bc749e3.bd1c78","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"ce09602b.03d27","type":"inject","z":"6bc749e3.bd1c78","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":160,"wires":[["fda2330d.8f348"]]},{"id":"fda2330d.8f348","type":"function","z":"6bc749e3.bd1c78","name":"Original data","func":"msg.payload = {\n\"deviceId\":\"B42EB8\",\n\"time\":\"2018-07-30T14:46:31.872257Z\",\n\"_msgid\":\"bca8ce3a.2962b\",\n\"seq\":\"\",\n\"dataView\":\"\",\n\"enters\":9866,\n\"exits\":11165,\n\"type\":\"string\",\n\"unit\":\"\",\n\"recep\":\"\",\n\"id\":\"\",\n\"MEE\":\"\",\n\"TWS\":0,\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":160,"wires":[["8e233d10.9df15"]]},{"id":"8e233d10.9df15","type":"function","z":"6bc749e3.bd1c78","name":"Transform original data","func":"let deviceId = msg.payload.deviceId;\nlet time = msg.payload.time;\nlet seq = msg.payload.seq;\n\nlet recep = {\n \"id\":msg.payload.id,\n \"MEE\":msg.payload.MEE,\n \"TWS\":msg.payload.TWS\n};\n\nlet enters = {\n \"key\":\"enters\",\n \"value\": msg.payload.enters,\n \"type\": msg.payload.type,\n \"unit\": msg.payload.unit\n};\n\nlet exits = {\n \"key\":\"exits\",\n \"value\": msg.payload.exits,\n \"type\": msg.payload.type,\n \"unit\": msg.payload.unit\n};\n\n\nmsg.payload = {\n \"deviceID\": deviceId, \n \"time\":time, \n \"seq\":seq,\n \"dataView\": [enters,exits],\n \"recep\": [recep]\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":160,"wires":[["597e7e14.9919b"]]},{"id":"597e7e14.9919b","type":"debug","z":"6bc749e3.bd1c78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":730,"y":160,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![kimou](https://avatars.discourse-cdn.com/v4/letter/k/b782af/32.png) [@kimou](https://discourse.nodered.org/u/kimou)
#### Post date: [31 July 2018 06:34 UTC](https://discourse.nodered.org/t/change-payload-include-array/1911/3 "2018-07-31T06:34:26Z")

</div>

Thank you very much @Andrei you saved my life
