Retain example message in JSONata Expression editor

I am a huge fan of the JSONata in Node-RED, particularly in the Switch node and the Change node. It beats the hell out of writing nested loops in a function node. It can make resonably complex and powerful no code flows possible.

The JSONata Expression editor has an example message can be used to test the expression you are wirting.

The example message likes to dissapear sometimes. It would be nice to retain the example message and not just revert back to a hello world payload example message. My current workaround is to keep a Template node with a copy of my test data below the affected Change or Switch nodes.

Not quite true as JSONata is a form of code, just saying.

As to request, i think this test data is held in the browser and any refresh will make it disappear.. A workaround to make it easier to reinstate, might be to hold it in the expression for easier copying and reinstating

$$.payload & " " & $$.topic
    "payload": "not hello world",
    "topic": "test"

Not perfect but easier to retrieve. Obviously for larger data examples this to may be a pain.
[edit] adding in a comment may be more efficient.
You could also add larger data in the node description tab.

Yes it is actually code and turing complete. But the one liner example aggregate array and transform JSON might just pass as a formula to the untrained eye. I stopped using powerapps when microsoft pulled the premium connector number in 2019 but some of my colleagues still use it and some of the no code "formulas" are just crazy and are trying to emulate code.

The C style comments /* multiple lines */ are allowed in JSONata. The // single line is not. << For anyone not familiar.

The new workaround is still a copy and paste exercise, albeit with less mouse clicks. But there is no warning that the example message will disapear on the next browser refresh and that caught me out a few times.

I still think the retain example message as default would be a good feature.
The back tick in your JSONata above appears to be unintentional.

Why not copy it to the 'Description' tab?

Well that is another feature request being heavily discussed. There is no indication that a node has a description.

The JSONata Example message never says it is not persistent and liable to disappear when the browser refreshes.
It should be consistent and disappear immediately on close and state that in the GUI or help OR it should just be persistent like everything else I type in is.

Sorry, I was referring to you copying he code into a different node. I often use a node's description tab to save code I am modifying so I can return if new code does not work.


I flagged this as a bug as Node-RED should not just forget about text I typed in and then deployed when the browser is refreshed.

1 Like