# Measurement and Tags are lost after parsing MQTT payload with xpath\_json

**URL:** <https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055>\
**Category:** Telegraf\
**Tags:** telegraf, mqtt, json\
**Created:** [February 1, 2024, 4:38pm UTC](https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055 "2024-02-01T16:38:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mourad](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@mourad](https://community.influxdata.com/u/mourad)\
**Post date:** [February 1, 2024, 4:38pm UTC](https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055/1 "2024-02-01T16:38:05Z")

</div>

Hello Community,

Thank you for your efforts !

This is my first experience with Telegraf and InfluxDB and I need your help.

I’m parsing the JSON payload sent from mqtt broker, the fieldset and timestamp are OK  
while the measurement and Tags are replaced with unexpected values:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/4/47adc010e8b3a09bf5f5474e52b005bdde298be3.png)

My MQTT Broker is sending the following json

```auto
{
    "fields": {
        "cache_size": 16384.0,
        "core_id": 0,
        "cpu_cores": 8,
        "vendor_id": "GenuineIntel"
    },
    "measurement": "cpuinfo",
    "tags": {
        "architecture": "x86_64",
        "cpuinfo_name": "proc0",
        "os": "Debian"
    },
    "time": "1706804130618257510"
}

```

**The Telegraf config:**

```auto
[[inputs.mqtt_consumer]]
  data_format = "xpath_json"
  servers = [
    "tcp://mosquitto.mosquitto-mqtt.svc.cluster.local:1883"
  ]
  topics = [
    "vvp.v1.detailed.metrics/#"
  ]
  [[inputs.mqtt_consumer.xpath]]
     metric_name = "measurement"
  [[inputs.mqtt_consumer.xpath]]
     metric_selection = "/measurement"
  [[inputs.mqtt_consumer.xpath]]
     timestamp = "/time"
  [[inputs.mqtt_consumer.xpath]]
     timestamp_format = "unix"
  [[inputs.mqtt_consumer.xpath]]
     field_selection = "/fields/*"
  [[inputs.mqtt_consumer.xpath]]
     tag_selection = "/tags/*"

```

Is there any thing missing ?

Thank you

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [February 1, 2024, 5:30pm UTC](https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055/2 "2024-02-01T17:30:21Z")

</div>

Hi,

> Is there any thing missing ?

You are actually defining too much 😉 Try this:

```toml
[[inputs.mqtt_consumer]]
  servers = [
    "tcp://mosquitto.mosquitto-mqtt.svc.cluster.local:1883"
  ]
  topics = [
    "vvp.v1.detailed.metrics/#"
  ]
  data_format = "xpath_json"
  [[inputs.mqtt_consumer.xpath]]
    metric_name = "/measurement"
    timestamp = "/time"
    timestamp_format = "unix"
    field_selection = "/fields/*"
    tag_selection = "/tags/*"

```

You don’t need to define a table for every single item.

---

<div class="post-metadata">

**Author:** ![mourad](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@mourad](https://community.influxdata.com/u/mourad)\
**Post date:** [February 2, 2024, 11:02am UTC](https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055/3 "2024-02-02T11:02:16Z")

</div>

Thank you @jpowers, It is working 🙂 after defining only one table for all items.

But Still having the topic in the line protocol :

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/a917078859a91796eca4d0aa3653d9702b72f855.png)

How can I remove it ?

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [February 2, 2024, 1:10pm UTC](https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055/4 "2024-02-02T13:10:23Z")

</div>

See the [tagexclude](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#modifiers) config option.

---

<div class="post-metadata">

**Author:** ![mourad](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@mourad](https://community.influxdata.com/u/mourad)\
**Post date:** [February 2, 2024, 1:31pm UTC](https://community.influxdata.com/t/measurement-and-tags-are-lost-after-parsing-mqtt-payload-with-xpath-json/33055/5 "2024-02-02T13:31:38Z")

</div>

Thank a lot @jpowers !

I added the **tagexclude** and it’s fixed !

```auto
[[inputs.mqtt_consumer]]
  data_format = "xpath_json"
  servers = [
    "tcp://mosquitto.mosquitto-mqtt.svc.cluster.local:1883"
  ]
  topics = [
    "vvp.v1.detailed.metrics/#"
  ]
  tagexclude = ["topic"]
  [[inputs.mqtt_consumer.xpath]]
     metric_name = "measurement"
     timestamp = "/time"
     timestamp_format = "unix"
     field_selection = "/fields/*"
     tag_selection = "/tags/*"

[[inputs.internal]]
  collect_memstats = false

```
