Change Node: JSONata misbehaving/expression disappearing intermittently

For some strange reason while I'm editing flows including Change Node with JSONata expressions, every so often the JSONata expression is disappearing completely from the Node.
Its hard to reproduce, but its happening after deploying and testing the node, so the rest of the flow is being saved ok and unaffected.
The Change node remains on the palette but the details within reverts to this empty shell

Not sure how to help myself or give more information to troubleshoot this one, the only other thing I have noticed with it this afternoon is some strange caching of values as I build up the JSONata expression, it has been adding in values into odd places in the output

Anyway the key issue is the disappearing expression.
Its unworkable in its current form, but I am assuming that I cant be alone?
My dev environment is on a virtual machine (Gitpod https://www.gitpod.io/ based) and the flows are getting backed up to a flow.json file regularly but the work on the Change node is disappearing in between those occasions while the rest of the session is going along fine.
Happy to try to test something /any tips welcome
thanks
Tony

Hi Tony,

we've not had any similar reports of problems with that node.

Can you please check the browser's javascript console for any errors or messages when you open the Change node edit dialog.

thanks Nick
Right now, no errors at all the console looks clean when I open it.

Its just happened to me again.. I have a session open.. edited Change node, added a jsonata expression, come out of it, gone to Inject node (JSON data) , taken a path from there, wanted to paste it into the JSONata expression and its all gone again
Console remains clear


Is there any other form of logging I could be doing to try to trace the issue?
thanks
Tony

PS I can try a screencast but dont think it will add much more than verification of my description

That is very strange - no there isn't any addition logging in this area because it all just works...

When it comes up blank, can you:

  1. hit Cancel

  2. open the Info sidebar and click the 'show more' link to see the full node properties:

    image

  3. once expanded, look at the rules section and confirm if it has anything in there.

We're trying to identify what the node configuration contains at this point in time - whether there are any rules known to the node or not.

ok I'll try it again a few times to try to recreate again

OK its not recurred yet but I may as well post the bizarre JSONata behaviour there too as that is back again (unless you want me to put in another post, but ? related, happy to post elsewhere just let me know)

See simple flow here

See inject/input JSON here


See JSONata expression and see the Output (2 debug nodes to show the pre JSONata and postJSONata JSON)

You'll note the key2 mapping is completely wrong, it should just map the clinical description but it has mapped the whole of the LabOrderDetails object within this JSON

Could you paste in a sample of the input JSON and the expression you are using? Save me retyping it out to test with :slight_smile:

Input

{
    "LabOrder": 1,
    "LabOrderDetails": {
        "DateTime": "19/11/2019 2pm",
        "Clinical Description": "Alert",
        "LabTestName": "Full Blood Count"
    }
}

JSONata expression

{
"key1": payload.LabOrderDetails.LabTestName,
"key2":payload.LabOrderDetails["Clinical Description"],
"key3":45,
"key4": true
}

I stripped the JSON down to be very basic/almost meaningless as was behaving oddly with a richer JSON object but wanted to pin the problem down..
You'll note the different syntax within, (.LabTestName versus ["Clinical Description"] ) the paths have been taken from the Copy Path aspect of the tooling and the difference must be down to the white space in the key name.

Tony, what you are seeing is the correct behavior... since JSONata !== JS

Let me explain... no, there is too much... let me sum up ;*)

The [ ... ] syntax refers to a predicate filter, meaning that it modifies the list of object(s) returned by payload.LabOrderDetails and returns only those where the string "Clinical Description" is "truthy" (which will ALWAYS be true). Therefore, you get the entire object.

The syntax you are looking for is payload.LabOrderDetails."Clinical Description", meaning to get the value of the "Clinical Description" property (the quotes are only necessary if the property name contains a space).

Certainly a minor-looking by important difference in the two syntaxes... it took me a few minutes to understand what was going on, since I'm normally in Javascript mode, too.

1 Like

Very many thanks for that spot @shrickus, certainly missed that

May take a bit to digest.. it also means that using the "Copy Path to Item" facility in the JSON editor cant be used for JSONata expressions without considering this..

thanks again & well spotted, appreciate the help and the tip

I need to try to reproduce the other disappearing JSONata expression, as usual hard to reproduce when under the spotlight

thanks again
Tony

Ah, nice catch yourself! I've never actually noticed that, but it does copy the path into a JS formatted syntax string, not JSONata... very interesting.