# I need to read the persistent data and combine it into a single piece of text

**URL:** <https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064>\
**Category:** General\
**Created:** [21 November 2021 12:58 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064 "2021-11-21T12:58:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [21 November 2021 12:58 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/1 "2021-11-21T12:58:24Z")

</div>

Hello, as shown in the picture  
 ![1111](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a48f301b06217e1e3c3f57512b21fed354e4c2bd.png)

I want to read them out and arrange them into a text  
The format looks like this:  
{"a": load\_\_v data, "b": fan\_v data, "c": fan\_A data}  
And so on  
I tried a lot of things but couldn't put them together  
Can you help me  
Thank you very much

---

<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:** [21 November 2021 13:08 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/2 "2021-11-21T13:08:25Z")

</div>

This is a job for the template node  
e.g.

```auto
[{"id":"b75fcc44.64f79","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":4840,"wires":[["fafe62fc.c05b88"]]},{"id":"fafe62fc.c05b88","type":"template","z":"b779de97.b1b46","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"a\": {{global.load_v}}, \"b\": {{global.fan_v}}, \"c\": {{global.fan_a}}}","output":"str","x":290,"y":4840,"wires":[["51b9b0de.3f9dd"]]},{"id":"51b9b0de.3f9dd","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":4840,"wires":[]}]

```

```auto
{"a": {{global.load_v}}, "b": {{global.fan_v}}, "c": {{global.fan_a}}}

```

from the template help info

> It is possible to use a property from the flow context or global context. Just use `{{flow.name}}` or `{{global.name}}` , or for persistable store `store` use `{{flow[store].name}}` or `{{global[store].name}}` .

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [21 November 2021 13:13 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/3 "2021-11-21T13:13:30Z")

</div>

That's great. He fulfilled my needs perfectly. Thank you very much

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 November 2021 13:31 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/4 "2021-11-21T13:31:12Z")

</div>

I am interested in knowing why you need to make a string of that form. It is not very common to need to do that.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [21 November 2021 13:34 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/5 "2021-11-21T13:34:03Z")

</div>

It is more complicated, I have someone customized a modbus to JSON device, his network data format is such.....

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 November 2021 13:44 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/6 "2021-11-21T13:44:32Z")

</div>

OK, the other way to do this would be to use a Change node to make a javascript object with those values, then feed it through a JSON node to convert it to JSON. There is no great advantage to doing it that way other than it reduces the likelihood of typos when building the JSON string manually.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [21 November 2021 13:46 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/7 "2021-11-21T13:46:45Z")

</div>

Can you send a routine  
I want to compare that

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 November 2021 13:59 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/8 "2021-11-21T13:59:06Z")

</div>

Here is the start of the Change node setup, you can add extra entries for the other data items. It starts by setting msg.payload to an empty object, then sets msg.payload.a to the global load\_v. Add the extra rows for the others.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae78469b994ae55306513d7fda3894dc9bb4a7f1.png)

Then feed that into a JSON node it will convert it to a JSON string.

---

<div class="post-metadata">

**Author:** ![Cybertron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cybertron/32/14683_2.png) [@Cybertron](https://discourse.nodered.org/u/Cybertron)\
**Post date:** [21 November 2021 14:08 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/9 "2021-11-21T14:08:55Z")

</div>

thank you  
I'll test this routine

---

<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:** [5 December 2021 14:09 UTC](https://discourse.nodered.org/t/i-need-to-read-the-persistent-data-and-combine-it-into-a-single-piece-of-text/54064/10 "2021-12-05T14:09:31Z")

</div>

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