# File-in node drops payload properties?

**URL:** https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724
**Category:** General
**Created:** [15 October 2019 07:57 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724 "2019-10-15T07:57:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 October 2019 07:57 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/1 "2019-10-15T07:57:13Z")

</div>

Consider following flow:

 ![55](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4bcafba0d329cbc2b644faec499699ef0d624bd8.jpeg)

Inject node sets `payload.category` to "Business" (this part will to become dynamic).  
Retrieve text file, `payload.category` is dropped.

In the change node I want to use jsonata:  
`*.$[$contains(categories, payload.category)]`

I could use "topic" instead in the inject node, but the change node cannot access msg.topic, only payload (in jsonata).

So next step would be to add another change node, faced following block:

1. If payload contains an array, one cannot set another property in payload. ie. move `msg.topic` to `msg.payload.category` - this seems to be ignored due to the existing array, is this correct ?
2. I have moved both the array to `msg.payload.channels` and topic to `msg.payload.category` - this works.
3. Can one use a "dynamic" value in jsonata ?

`payload.channels.$[$contains(tv_categories,"Business")]` works  
`payload.channels.$[$contains(tv_categories, payload.category)]` does not want to work

---

<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: [15 October 2019 09:12 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/2 "2019-10-15T09:12:28Z")

</div>

> [@bakman2](#):
>
> but the change node cannot access msg.topic, only payload (in jsonata).

No, the Change node can access _any_ message property. You probably need to use `$$.topic` in your expression so it knows you want to refer to a property from the root and not the current position.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 October 2019 13:16 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/3 "2019-10-15T13:16:29Z")

</div>

Forgot about the `$$` - true, did not work for the `contains` function however.

```auto
payload.channels.$[$contains(tv_categories, $$.category)]

```

![50](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8822dd2239b0f603741c98a12e442e097668702e.jpeg)

@knolleary - is this statement correct ?

> 1. If payload contains an array, one cannot set another property in payload. ie. move `msg.topic` to `msg.payload.category` - this seems to be ignored due to the existing array, is this correct ?

---

<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: [15 October 2019 15:11 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/4 "2019-10-15T15:11:00Z")

</div>

Arrays can have 'other' properties. I don't know whether JSONata would know how to deal with them however.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 October 2019 15:16 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/5 "2019-10-15T15:16:46Z")

</div>

This is not related to the array actually, the question is for the change node. If I "move" msg.topic to msg.payload.category, while there is an array in payload, the change node will not add msg.payload.category.

Solution for jsonata found: `payload[$contains(tv_categories,$$.topic)]` (changed everything back to original and search the array directly instead).

---

<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: [15 October 2019 15:18 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/6 "2019-10-15T15:18:01Z")

</div>

Whilst a JavaScript Array may allow properties, a JSON Array won't.

If you want additional properties on `msg.payload` then it should be an object.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 October 2019 15:19 UTC](https://discourse.nodered.org/t/file-in-node-drops-payload-properties/16724/7 "2019-10-15T15:19:25Z")

</div>

That makes sense indeed: it is an array. Got it thanks a lot (again).
