# Formatting MQTT-output

**URL:** https://community.influxdata.com/t/formatting-mqtt-output/32110
**Category:** Systems
**Tags:** telegraf
**Created:** [November 11, 2023, 1:17pm UTC](https://community.influxdata.com/t/formatting-mqtt-output/32110 "2023-11-11T13:17:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Koenraad](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Koenraad](https://community.influxdata.com/u/Koenraad)
#### Post date: [November 11, 2023, 1:17pm UTC](https://community.influxdata.com/t/formatting-mqtt-output/32110/1 "2023-11-11T13:17:23Z")

</div>

Hi,  
Rather new with telegraf and I’m having a problem.  
I’m reading data from modbus, that’s OK.  
My problem is that I need some of that data sent to MQTT in JSON-format. That works, but only partially.  
The data I need to send to MQTT is like this :

```auto
{
  "Pac" : 175.0,
  "E-Total" : 40834.27
}

```

What I succeeded to do is this :

```auto
{
  "fields" : {
    "E-Total" : 58343,
    "Pac" : 330
  },
  "name" : "modbus",
  "tags" : {
    "dc" : "server1",
    "host" : "server1",
    "name" : "SMA-inverter1",
    "slave_id" : "3",
    "type" : "holding_register"
  },
  "timestamp" : 1699707510
}

```

The device that is subscribed to the topic can’t handle this.  
How do I remove those “superfluous” items ?  
I tried using `layout = "field"`, but then, the data is not JSON-formatted, it’s just two new topics.  
I was suggested to read [this](https://community.influxdata.com/t/problems-with-json-transformation-in-telegraf-outputs-mqtt/31751). Is that the way to go ? If yes, where can I find the documentation (plugins ?) ?  
Thanks.

---

<div class="post-metadata">

### Author: ![Koenraad](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Koenraad](https://community.influxdata.com/u/Koenraad)
#### Post date: [November 11, 2023, 2:02pm UTC](https://community.influxdata.com/t/formatting-mqtt-output/32110/2 "2023-11-11T14:02:51Z")

</div>

Replying to my own post 🥶  
After reading/searching more I found this :

```auto
json_transformation = '''
        $merge([fields])
'''

```

Now it works.

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [November 16, 2023, 7:49am UTC](https://community.influxdata.com/t/formatting-mqtt-output/32110/3 "2023-11-16T07:49:06Z")

</div>

Hello @Koenraad,  
Thank you for including a solution to your answer!
