# How to add an json object to an array

**URL:** <https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871>\
**Category:** General\
**Created:** [7 October 2020 09:12 UTC](https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871 "2020-10-07T09:12:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [7 October 2020 09:12 UTC](https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871/1 "2020-10-07T09:12:35Z")

</div>

I have a `msg.arrFile` array.

I researched then there is a method `$append(array1, array2)`, but returns an array containing the values in array1 followed by the values in array2  
[https://docs.jsonata.org/array-functions#append](https://docs.jsonata.org/array-functions#append)

Is there a way to add the json object that is the information of a file to `msg.arrFile` without using the `function` node?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 October 2020 09:19 UTC](https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871/2 "2020-10-07T09:19:04Z")

</div>

Hi @minhhn0205

Can you provide an example of the data you have in `msg` and what you want the result to look like?

---

<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 October 2020 11:30 UTC](https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871/3 "2020-10-07T11:30:56Z")

</div>

Here is a simple example, hope it helps. Notice the  
[] around the object

```auto
[{"id":"187967a.a95e618","type":"inject","z":"4484ee28.caa3c","name":"","props":[{"p":"payload"},{"p":"object","v":"{\"1\":1,\"2\":2}","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3]","payloadType":"json","x":130,"y":500,"wires":[["4119a2a6.a337dc"]]},{"id":"4119a2a6.a337dc","type":"change","z":"4484ee28.caa3c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$append(payload, [object])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":500,"wires":[["269a25ff.79887a"]]},{"id":"269a25ff.79887a","type":"debug","z":"4484ee28.caa3c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":360,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [7 October 2020 15:05 UTC](https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871/4 "2020-10-07T15:05:03Z")

</div>

> [@E1cid](#):
>
> [] around the object

Great, thank you very much for the effort! \<3

---

<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:** [21 October 2020 15:05 UTC](https://discourse.nodered.org/t/how-to-add-an-json-object-to-an-array/33871/5 "2020-10-21T15:05:19Z")

</div>

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