Club all MQTT Topic data in one json string


How can I club all the MQTT Topic data in one JSON String
I was able to get JSON string for the individual topic only like this


but I want to display all the topic data in one JSON string only for example


I am using mentioned below code in function node

var topic = msg.topic;
var d = new Date();
var t = d.getTime();
payload = {"time":t, "payload" : msg.payload ,"topic": topic }
msg.payload = payload;
return msg;

what modification will help me to make it work?
Any suggestion on this will be a great help



Hi @Varul92

The Join node can be used to group messages into one. If you configure it to create a key/value Object, and tell it how many different topics you are working with, it will group the messages together and send one on once it has a complete set.



Hi @knolleary

Thanks for the update, I am able to do it with join node but the sensor data is displaying in the same line like


But is it possible to display it in the next line like this



You said you wanted a JSON string.

The example you now give isn’t JSON (no commas between name value pairs).

But now you have the data as a javascript object, you can pass it through the JSON node to get a JSON string and then use a change node to modify the JSON into the string you want