Guide to using JSON option in change node

I basically would like to amalgamate two items into a combined JSON object/string

e.g

I've got msg.tweethandle and msg.tweettxt - how do I use the JSON option in the change node to make msg.payload = { msg.tweethandle : msg.tweettxt} (the contents of them - not those literal words)

Or is that not what its for?

or have I lost the JSON plot entirely again?

Simon

The JSON option doesn't include any way to reference the received message properties when constructing its object.

You should use the Expression option instead:

{$.tweethandle: $.tweettxt}
1 Like

If you use the JSONata option (J:) you can Set msg.payload To msg.tweethandle&msg.tweettxt which will concatenate the two strings.

[Edit] I see I misread the requirement. :frowning:

1 Like

Ta for info

I've ended up with this as I realised I needed to have fixed keys for each value (and I even surpassed myself by working out that I needed a JSON node to convert it to an object afterwards :slight_smile: )

image

2 Likes

You should be able to do that with just the JSONata I think.

From this example, you can see that you can access both the topic and the payload directly.

1 Like

Of course - I was just taking little steps one at a time :slight_smile: