# I want to rewrite the data in the template, but it all becomes \[object Object\]

**URL:** https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315
**Category:** General
**Created:** [7 January 2023 03:43 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315 "2023-01-07T03:43:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![TOSHI1](https://avatars.discourse-cdn.com/v4/letter/t/7ba0ec/32.png) [@TOSHI1](https://discourse.nodered.org/u/TOSHI1)
#### Post date: [7 January 2023 03:43 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/1 "2023-01-07T03:43:27Z")

</div>

[![Image from Gyazo](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0508c2e5eff0a199b2496f8b9a0a19cc0cb2daa.png)](https://gyazo.com/19c3cfcde4734456e8ba45e2f444a56e)

I want to rewrite the data in the template as shown in the image, but it all becomes [object Object]. Is there a way to rewrite the contents of the data?

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [7 January 2023 04:20 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/2 "2023-01-07T04:20:14Z")

</div>

It would help if you show what is in payload.values.

---

<div class="post-metadata">

### Author: ![TOSHI1](https://avatars.discourse-cdn.com/v4/letter/t/7ba0ec/32.png) [@TOSHI1](https://discourse.nodered.org/u/TOSHI1)
#### Post date: [7 January 2023 04:38 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/3 "2023-01-07T04:38:32Z")

</div>

Thank you very much. The contents are as stated below.

[  
{  
"Species": "Adelie",  
"Island": "Torgersen",  
"Beak Length (mm)": 39.5,  
"Beak Depth (mm)": 17.4,  
"Flipper Length (mm)": 186,  
"Body Mass (g)": 3800,  
"Sex": "FEMALE"  
},  
{  
"Species": "Adelie",  
"Island": "Torgersen",  
"Beak Length (mm)": 39.5,  
"Beak Depth (mm)": 17.4,  
"Flipper Length (mm)": 186,  
"Body Mass (g)": 3800,  
"Sex": "FEMALE"  
}  
]

---

<div class="post-metadata">

### Author: ![TOSHI1](https://avatars.discourse-cdn.com/v4/letter/t/7ba0ec/32.png) [@TOSHI1](https://discourse.nodered.org/u/TOSHI1)
#### Post date: [7 January 2023 04:50 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/4 "2023-01-07T04:50:37Z")

</div>

Below is a simplified flow

```auto
[{"id":"2f182f36.5de67","type":"template","z":"2eb2befc.213bf2","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.json\",\n \"description\": \"A vertical box plot showing median, min, and max body mass of penguins.\",\n \"width\": 500,\n \"height\": 500,\n \"padding\": 35,\n \"config\": {\n \"axis\": {\n\n \"labelColor\": \"#333333\",\n \"gridWidth\":1\n }\n },\n \"data\":{\"values\":\"{{payload}}\"},\n \"mark\": {\"type\": \"boxplot\", \"size\": 34,\"extent\": 1.5,\n \"median\": {\"color\": \"red\"},\n \"ticks\": true},\n \"encoding\": {\n \"x\": {\"field\": \"Species\", \"type\": \"nominal\"},\n \"color\": {\"field\": \"Species\", \"type\": \"nominal\", \"legend\": null},\n \"y\": {\n \"field\": \"Body Mass (g)\",\n \"type\": \"quantitative\",\n \"scale\": {\"zero\": false}\n }\n }\n}","output":"json","x":340,"y":100,"wires":[["f17281c5.4eee5"]]},{"id":"f17281c5.4eee5","type":"debug","z":"2eb2befc.213bf2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":60,"wires":[]},{"id":"3f261860.afae28","type":"inject","z":"2eb2befc.213bf2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Bod\":3800},{\"Bod\":3800}]","payloadType":"json","x":150,"y":100,"wires":[["750d1328.7b62ac","2f182f36.5de67"]]},{"id":"750d1328.7b62ac","type":"debug","z":"2eb2befc.213bf2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[0]","targetType":"msg","statusVal":"","statusType":"auto","x":330,"y":60,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)
#### Post date: [7 January 2023 04:57 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/5 "2023-01-07T04:57:23Z")

</div>

`JSON.stringify(...)` ?

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 January 2023 08:27 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/6 "2023-01-07T08:27:47Z")

</div>

Or JSONata in a change node to create a string of the object, no quotes required.  
e.g.

```auto
[{"id":"3f261860.afae28","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Bod\":3800},{\"Bod\":3800}]","payloadType":"json","x":150,"y":2200,"wires":[["04d423388a8e526e"]]},{"id":"04d423388a8e526e","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload[0]","pt":"msg","to":"$string($$.payload[0])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":2260,"wires":[["2f182f36.5de67","750d1328.7b62ac"]]},{"id":"2f182f36.5de67","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.json\",\n \"description\": \"A vertical box plot showing median, min, and max body mass of penguins.\",\n \"width\": 500,\n \"height\": 500,\n \"padding\": 35,\n \"config\": {\n \"axis\": {\n\n \"labelColor\": \"#333333\",\n \"gridWidth\":1\n }\n },\n \"data\":{\"values\":{{{payload.0}}} },\n \"mark\": {\"type\": \"boxplot\", \"size\": 34,\"extent\": 1.5,\n \"median\": {\"color\": \"red\"},\n \"ticks\": true},\n \"encoding\": {\n \"x\": {\"field\": \"Species\", \"type\": \"nominal\"},\n \"color\": {\"field\": \"Species\", \"type\": \"nominal\", \"legend\": null},\n \"y\": {\n \"field\": \"Body Mass (g)\",\n \"type\": \"quantitative\",\n \"scale\": {\"zero\": false}\n }\n }\n}","output":"json","x":500,"y":2260,"wires":[["f17281c5.4eee5"]]},{"id":"750d1328.7b62ac","type":"debug","z":"da8a6ef0b3c9a5c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[0]","targetType":"msg","statusVal":"","statusType":"auto","x":330,"y":2160,"wires":[]},{"id":"f17281c5.4eee5","type":"debug","z":"da8a6ef0b3c9a5c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":2260,"wires":[]}]

```

---

<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: [8 March 2023 08:28 UTC](https://discourse.nodered.org/t/i-want-to-rewrite-the-data-in-the-template-but-it-all-becomes-object-object/73315/7 "2023-03-08T08:28:36Z")

</div>

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