Json_v2 array of objects parsing with mqtt consumer

Hi, I’m having trouble with parsing mqtt consumer data in the form of a json array containing multiple object entries.

My json array looks like this:


My telegraf.conf file mqtt.consumer looks like this:

  servers = ["hivemq-server:8883"]
  topics = ["name/product/metrics/+"]
  qos = 2
  connection_timeout = "30s"
  persistent_session = true
  client_id = "telegraf"
  username = "username"
  password = "password"

    topic = "name/product/metrics/+"
    tags = "_/_/_/id"

  data_format = "json_v2"
  name_override = "logging_data"
      id = "uint"
      time = "uint"
      pressure = "float"
      t11 = "float"
      t12 = "float"
      t1out = "float"
      interval1 = "uint"

But I’ve already tried a number of different configuration options, including wrapping the fields in a [[inputs.mqtt_consumer.json_v2.object]] with path = “@this”.

The error I’m getting is the following:
error loading config file /etc/telegraf/telegraf.conf: plugin inputs.mqtt_consumer: line 128: configuration specified the fields ["json_v2"], but they weren't used

I’m running telegraf in a docker container.

Thanks for your help in advance.

You might want to use the xpath parser:

  data_format = "xpath_json"
  xpath_native_types = true

    metric_name = "'logging_data'"
    metric_selection = "child::*"
    field_selection = "*"