Json expression


#1

Hi. Is it possible to get rid of one of the function nodes. I want to combine the two messages sia_code and sia_address in the same function node. I want the output message to be 13ZO

/Niclas


#2

Hi @niclas.w82

Your question is missing some context. Which function nodes are you referring to? Is there a previous topic on the forum with more background to your question?


#3

Sorry forgot the picture


#4

Anyone knows if this is possible?


#5

Yes. You can do that in a change node with JSONata. Have a go yourself, I think you will find it fairly easy since you only need to create a simple string output.


#6

Ok. JSONata is something totally new to me. But tried this. Any idea?


#7

You are some way out in your object/property reference I'm afraid.

You would, I think - hard to say without more context - at least need:

msg.payload.data.sia.sia_code

And the same for sia_address.

To get the exact object reference, in the debug window, over the line containing the code or address entries, you will see some small icons appear to the right of the line. Click on the one that looks like >_ and it will tell you that it has copied the path.

image

Paste that into your code.


#8

Hi @niclas.w82

the JSONata Expressions can only be used in the Change node, where the input is set to the Expression type.

You are showing a screenshot of a Function node - that uses JavaScript.

So rather than use & to join strings, you need to use +.

But you also need to get the reference to the property right as @TotallyInformation describes above.


#9

Getting closer. Tried with + but it doesn't work in the test. Now I get the result I want but in the debug window it just look like this " " and I cannot understand why?


#10

In the Expression editor you are use data.sia.sia_code... but your previous screenshot showed that data was under msg.payload. So you should use payload.data.sia.sia_code in your expression - just as @TotallyInformation suggested.


#11

Because your example message is NOT what is incoming. You've only shown the msg.payload part.

You need the example to look like:

{"payload": {"status": ...... } }

#12

Finally solved!

Thank you all for your help!!!

/Niclas