# Telegraf parse Mqtt payload

**URL:** <https://community.influxdata.com/t/telegraf-parse-mqtt-payload/39359>\
**Category:** Telegraf\
**Tags:** influxdb, telegraf, json\
**Created:** [November 18, 2024, 10:56pm UTC](https://community.influxdata.com/t/telegraf-parse-mqtt-payload/39359 "2024-11-18T22:56:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rosario\_Iameo](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/rosario_iameo/32/16190_2.png) [@Rosario\_Iameo](https://community.influxdata.com/u/Rosario_Iameo)\
**Post date:** [November 18, 2024, 10:56pm UTC](https://community.influxdata.com/t/telegraf-parse-mqtt-payload/39359/1 "2024-11-18T22:56:00Z")

</div>

Hi all,  
im tring to pars the payload of topics from mqtt brokerwith telegraf but i dont undestand how it work with json\_v2 parser.  
the json object is :  
{  
“metrics”: [  
{  
“alias”: 2,  
“datatype”: 9,  
“name”: “01TT101”,  
“timestamp”: 1731970320000,  
“value”: 21.51331329345703  
},  
{  
“alias”: 3,  
“datatype”: 9,  
“name”: “01JT001\_Energy”,  
“timestamp”: 1731970320000,  
“value”: 430  
},  
{  
“alias”: 4,  
“datatype”: 9,  
“name”: “01JT001\_Flow”,  
“timestamp”: 1731970320000,  
“value”: 0  
}]

I would likt to parse it to have a metrics with name , value and timestamp to save in influx db.

is there somebody can explin me how it work the json\_v2 parser?

thanks in advance

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [December 11, 2024, 1:13pm UTC](https://community.influxdata.com/t/telegraf-parse-mqtt-payload/39359/2 "2024-12-11T13:13:37Z")

</div>

@Rosario_Iameo I suggest to use the [XPath parser](https://github.com/influxdata/telegraf/tree/master/plugins/parsers/xpath) here as it is easier to use and can handle lists better than the JSON v2 one. With the config

```toml
[[inputs.mqtt_consumer]]
  ...

  data_format = "xpath_json"
  xpath_native_types = true

  [[inputs.mqtt_consumer.xpath]]
    metric_name = "'sensors'"
    metric_selection = "/metrics/*"
    timestamp = "timestamp"
    timestamp_format = "unix_ms"

    [inputs.mqtt_consumer.xpath.fields]
      value = "value"

    [inputs.mqtt_consumer.xpath.tags]
      name = "name"

```

you will get the following metrics

```plaintext
> sensors,host=Hugin,name=01TT101 value=21.51331329345703 1731970320000000000
> sensors,host=Hugin,name=01JT001_Energy value=430 1731970320000000000
> sensors,host=Hugin,name=01JT001_Flow value=0 1731970320000000000

```
