# Load multi dim array variable content from file

**URL:** <https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584>\
**Category:** General\
**Created:** [9 June 2024 21:06 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584 "2024-06-09T21:06:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonnyTech](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jonnytech/32/93759_2.png) [@JonnyTech](https://discourse.nodered.org/u/JonnyTech)\
**Post date:** [9 June 2024 21:06 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584/1 "2024-06-09T21:06:59Z")

</div>

I have a flow variable (`flow.set('settings-array',[6][6])`) that I save to a json file. Here is a minimal flow to demonstrate:

```auto
[{"id":"5b2e4968d88ade34","type":"file","z":"b5cfb072d3d83deb","name":"","filename":"./settings-array.json","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":670,"y":440,"wires":[[]]},{"id":"cca1a262e2786e7d","type":"json","z":"b5cfb072d3d83deb","name":"","property":"payload","action":"","pretty":false,"x":490,"y":440,"wires":[["5b2e4968d88ade34"]]},{"id":"96feb5edcc2a0ccf","type":"function","z":"b5cfb072d3d83deb","name":"","func":"node.send({payload:flow.get('settings-array')});\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":480,"wires":[["cca1a262e2786e7d","219d7d10a48c6c88"]]},{"id":"6cf7827d48dd953b","type":"inject","z":"b5cfb072d3d83deb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":480,"wires":[["96feb5edcc2a0ccf"]]},{"id":"219d7d10a48c6c88","type":"debug","z":"b5cfb072d3d83deb","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":500,"wires":[]}]

```

This works well and upon examining the file content, I have all the data there.

But I cannot figure out how to load it back in from the file to the variable. Any suggestions please?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 June 2024 21:14 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584/2 "2024-06-09T21:14:51Z")

</div>

If you save the data as JSON you can simply pass it through a JSON node to recreate it.

Array -\> JSON node -\> write file

Read file -\> JSON node -\> array

Alternatively, you could just use persistent context?

---

<div class="post-metadata">

**Author:** ![JonnyTech](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jonnytech/32/93759_2.png) [@JonnyTech](https://discourse.nodered.org/u/JonnyTech)\
**Post date:** [9 June 2024 21:31 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584/3 "2024-06-09T21:31:48Z")

</div>

> Read file -\> JSON node -\> array

I have been trying but no luck yet (only been using node-red for a few days so still learning)

> persistent context

Something to read up on. Thank you.

But I am saving the values to share them on another computer.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 June 2024 07:27 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584/4 "2024-06-10T07:27:59Z")

</div>

Here is a demo  
 ![chrome_mzHGI4GD1j](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51a1d2fdb83a63dfd8b7209363cc2c2db6d62039.gif)

```auto
[{"id":"5b2e4968d88ade34","type":"file","z":"99e019d5.6f0748","name":"","filename":"./settings-array.json","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":930,"y":240,"wires":[[]]},{"id":"6cf7827d48dd953b","type":"inject","z":"99e019d5.6f0748","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":240,"wires":[["6b898c5a6fc321c0"]]},{"id":"3482428ce7520a99","type":"inject","z":"99e019d5.6f0748","name":"dummy data [[1,2,3],[4,5,6]]","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[1,2,3],[4,5,6]]","payloadType":"json","x":450,"y":120,"wires":[["eeb467cd1da1d9b6"]]},{"id":"eeb467cd1da1d9b6","type":"change","z":"99e019d5.6f0748","name":"","rules":[{"t":"set","p":"settings-array","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":140,"wires":[["d45a25ffbb5882d5"]]},{"id":"e9ae184d298ba242","type":"inject","z":"99e019d5.6f0748","name":"dummy data [[3,3,3],[6,6,6]]","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[3,3,3],[6,6,6]]","payloadType":"json","x":450,"y":160,"wires":[["eeb467cd1da1d9b6"]]},{"id":"6b898c5a6fc321c0","type":"change","z":"99e019d5.6f0748","name":"get flow.settings-array","rules":[{"t":"set","p":"payload","pt":"msg","to":"settings-array","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":240,"wires":[["5b2e4968d88ade34"]]},{"id":"7684ecc471f8bb5e","type":"inject","z":"99e019d5.6f0748","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":300,"wires":[["d5022c077495716b"]]},{"id":"d5022c077495716b","type":"file in","z":"99e019d5.6f0748","name":"","filename":"./settings-array.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":590,"y":300,"wires":[["ab92e2c699ea8138"]]},{"id":"ab92e2c699ea8138","type":"json","z":"99e019d5.6f0748","name":"","property":"payload","action":"","pretty":false,"x":750,"y":300,"wires":[["2e1fdaf7cda04859"]]},{"id":"2e1fdaf7cda04859","type":"change","z":"99e019d5.6f0748","name":"","rules":[{"t":"set","p":"settings-array","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":300,"wires":[[]]},{"id":"d45a25ffbb5882d5","type":"debug","z":"99e019d5.6f0748","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":140,"wires":[]},{"id":"a751542558043510","type":"debug","z":"99e019d5.6f0748","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":380,"wires":[]},{"id":"d60b14d75da86f01","type":"inject","z":"99e019d5.6f0748","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":380,"wires":[["bd7c9f17b6b9da59"]]},{"id":"bd7c9f17b6b9da59","type":"change","z":"99e019d5.6f0748","name":"get flow.settings-array","rules":[{"t":"set","p":"payload","pt":"msg","to":"settings-array","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":380,"wires":[["a751542558043510"]]}]

```

---

<div class="post-metadata">

**Author:** ![JonnyTech](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jonnytech/32/93759_2.png) [@JonnyTech](https://discourse.nodered.org/u/JonnyTech)\
**Post date:** [10 June 2024 11:35 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584/5 "2024-06-10T11:35:06Z")

</div>

Wow, @Steve-Mcl, I cannot believe that you took the effort to create that, thank you very much indeed, it filled a gap in my knowledge and I am on the correct path now.

---

<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:** [24 June 2024 11:35 UTC](https://discourse.nodered.org/t/load-multi-dim-array-variable-content-from-file/88584/6 "2024-06-24T11:35:11Z")

</div>

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