# Parsing an array from an MQTT topic with json\_v2

**URL:** https://community.influxdata.com/t/parsing-an-array-from-an-mqtt-topic-with-json-v2/26682
**Category:** Telegraf
**Tags:** telegraf, mqtt, json
**Created:** [September 23, 2022, 8:29am UTC](https://community.influxdata.com/t/parsing-an-array-from-an-mqtt-topic-with-json-v2/26682 "2022-09-23T08:29:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![oh2th](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/oh2th/32/11034_2.png) [@oh2th](https://community.influxdata.com/u/oh2th)
#### Post date: [September 23, 2022, 8:29am UTC](https://community.influxdata.com/t/parsing-an-array-from-an-mqtt-topic-with-json-v2/26682/1 "2022-09-23T08:29:06Z")

</div>

I have a mqtt topic that contains an array as “[aa.a,bb.b]” and seems that my configuration is working more or less as the desired values arrive all the way to the influxdb. However testing the configuration does give errors and outputs twice the line protocol line related to this consumer.

Input from MQTT:

```auto
go-eCharger/201397/nrg = [233.74,2.48,3.41,1.24,0,0,0,0,0,0,0,0,0,0,0,0]
go-eCharger/201397/tma = [35.5,30.5]

```

Currently only setting up parsing for the `tma` variable. Once that works will do `nrg` also.

Configuration for telegraf:

```auto
[[inputs.mqtt_consumer]]
  servers = ["tcp://localhost:1883"]
  topics = [
    "go-eCharger/+/tma", # temperature sensors
  ]

  data_format = "json_v2"
  topic_tag = ""

  connection_timeout = "30s"
  qos = 0
  username = "telegraf"
  password = "Password"

  [[inputs.mqtt_consumer.topic_parsing]]
    topic = "go-eCharger/+/+"
    measurement = "measurement/_/_"
    tags = "_/chargerid/_"

  [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "@this"
      optional = true
      tags = [""]
      fields = [""]
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "0"
        rename = "t1"
        type = "float"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "1"
        rename = "t2"
        type = "float"

```

Output from test:

```auto

2022-09-23T08:05:41Z D! [serializers.influx] could not serialize field "": invalid field key; discarding field
> go-eCharger,chargerid=201397 t1=26,t2=21 1663920341263071772
2022-09-23T08:05:41Z D! [serializers.influx] could not serialize field "": invalid field key; discarding field
> go-eCharger,chargerid=201397 t1=26,t2=21 1663920341263071772

```

What should I change, to get the serializer error away? Or should I just ignore the error, also the line protocol is sent out for every field match. the serializer errors appear also in /var/log/telegraf.log and would fill up the local storage quite soon unless i can figure out what to change in the config to be valid.

---

<div class="post-metadata">

### Author: ![oh2th](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/oh2th/32/11034_2.png) [@oh2th](https://community.influxdata.com/u/oh2th)
#### Post date: [September 25, 2022, 4:07am UTC](https://community.influxdata.com/t/parsing-an-array-from-an-mqtt-topic-with-json-v2/26682/2 "2022-09-25T04:07:48Z")

</div>

After debugging the serializing issue in my configuration, I found out that it was related to using `json_v2.object` which resulted with an unnecessary empty object.

By removing

```auto
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "@this"
      optional = true
      tags = [""]
      fields = [""]

```

And leaving just the two `json_v2.field` statements, I was able to get rid of the error, and the two values for `t1` and `t2` are now updated correctly.

---

<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: [September 26, 2022, 9:17pm UTC](https://community.influxdata.com/t/parsing-an-array-from-an-mqtt-topic-with-json-v2/26682/3 "2022-09-26T21:17:15Z")

</div>

@oh2th Thank you for sharing your solution! We really appreciate it.
