# Club all MQTT Topic data in one json string

**URL:** <https://discourse.nodered.org/t/club-all-mqtt-topic-data-in-one-json-string/7773>\
**Category:** General\
**Created:** [9 February 2019 19:00 UTC](https://discourse.nodered.org/t/club-all-mqtt-topic-data-in-one-json-string/7773 "2019-02-09T19:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varul92](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@Varul92](https://discourse.nodered.org/u/Varul92)\
**Post date:** [9 February 2019 19:00 UTC](https://discourse.nodered.org/t/club-all-mqtt-topic-data-in-one-json-string/7773/1 "2019-02-09T19:00:00Z")

</div>

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

```
 "{"time":1549737900821,"payload":"1997.32","topic":"RotateZ"}"
  {"time":1549737900821,"payload":"1954.32","topic":"RotateY"}"

```

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

```
`"{"time":1549737900821,
    "RotateZ":"1997.32",
    "RotateY":"1954.32"}"`

```

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [9 February 2019 20:04 UTC](https://discourse.nodered.org/t/club-all-mqtt-topic-data-in-one-json-string/7773/2 "2019-02-09T20:04:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Varul92](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@Varul92](https://discourse.nodered.org/u/Varul92)\
**Post date:** [10 February 2019 05:56 UTC](https://discourse.nodered.org/t/club-all-mqtt-topic-data-in-one-json-string/7773/3 "2019-02-10T05:56:41Z")

</div>

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

`{"AccelX":"0.26","AccelY":"0.00","AccelZ":"0.01","RotateX":"1996.10","RotateY":"0.43","RotateZ":"1996.68"}`

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

```
{
"AccelX":"0.26"
"AccelY":"0.00"
"AccelZ":"0.01"
"RotateX":"1996.10"
"RotateY":"0.43"
"RotateZ":"1996.68"
}
```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [10 February 2019 07:01 UTC](https://discourse.nodered.org/t/club-all-mqtt-topic-data-in-one-json-string/7773/4 "2019-02-10T07:01:19Z")

</div>

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
