I end up using a (simple) JSONata expression to append text to existing msg.payloads (e.g when sending tweets out)
Is there a none JSONata/JS way of doing this?
If not, how about adding Append as an option in the change node (as well as set,change,move,delete)?
1 Like
The trouble is you then start down the slippery slope of all the various operations possible.
If we added append, why not prepend, split, trim, indexOf etc - and that's just for String types. For arrays - push,pop,slice and so on.
That may be something to consider, but it risks throwing too many options in the node.
Someone already has created a node for Strings - https://flows.nodered.org/node/node-red-contrib-string
I was only after a LITTLE bit of cream on top........
your right, we'd need prepend as well
but that's all
I'm not normally one for pointing out what happens elsewhere to boost my case but....
...the switch node has a LOT of options
And I see the change node as its main companion.
The more things that can be achieved by these two nodes without resorting to code or contrib nodes would be good for Node-RED?
It is worth considering, but not by adding one option at a time.
Colin
18 August 2018 08:40
6
I tried this. I thought I should be able to use a Change node to Set msg.payload to
payload & "extra text"
but the JSONata window doesn't like it. Using node-red v0.18.7
mm -works for me (in 0.19.1) and it always worked for me in 0.18.7 as well
Colin
18 August 2018 08:58
8
Sorry, just me being careless, I had JSON instead of J:
So given that it is so easy(!) I can't see that it is worth adding a specific Append option.
well... I think one of the the main selling points of Node-RED is NOT having to code to achieve simple (or even quite complex) things hence my request
JFI - This all came about by me looking thru my change nodes and seeing which ones had JSONata in them and then seeing if I could use @BartButenaers Blocky node instead
And I found that quite a few of them were just using JSONata to prepend/append text/flowContext stuff to a payload
Simon
There is a pretty simple way to append (or prepend) using a change
node with regex:
... as long as you know that ^
means "start of string", and $
means "end of string".
4 Likes
well.......
is using RegEx programming?
Discuss
2 Likes