File-in node drops payload properties?

Consider following flow:

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

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.

1 Like

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

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

50

@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 ?

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

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).

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.

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