Error parsing array with json_v2 on mqtt_consumer

I’m currently testing sending an mqtt payload with an array of json objects to reduce message count. I successfully configured the json_v2 parser for a single object, and the object schema has not changed. Now when the messages are received I get an error:

2022-02-23T20:50:22+13:00 E! [inputs.mqtt_consumer] Error in plugin: GJSON Path returned null, either couldn't find value or path has null value

The object schema is simple (no nesting). A simplified example of the schema is:

   "timestamp": 1645603701123,
   "someValue": 23

So now I’m sending:

    "timestamp": 1645603701123,
    "someValue": 23
    "timestamp": 1645603701132,
    "someValue": 34

From the documentation I was expecting the plugin to parse each object in the array using the same configuration. Is that not the case? Do I need to adapt my json_v2 config for the array?

Please show us the config of your mqtt plugin.

1 Like

Here’s the simplified config example:

 servers = [hidden]
 topics = [
 qos = 1
 max_undelivered_messages = 10000
 persistent_session = true
 client_id = "telegraf"
 tls_ca = "/etc/telegraf/certs/ca.pem"
 tls_cert = "/etc/telegraf/certs/cert.pem"
 tls_key = "/etc/telegraf/certs/key.pem"
 data_format = "json_v2"
   topic = "+/+/+/+/+"
   measurement = "_/_/_/_/measurement"
   tags = "_/org/thing_type/thing_id/_"
   timestamp_path = "timestamp"
   timestamp_format = "unix_ms"
     path = "someValue"
     type = "int"

Try this config:

# other config
# ...
      path = "@this"
      timestamp_key = "timestamp"
      timestamp_format = "unix_ms"
        someValue = "int"
1 Like

Thanks, I tried that config and now there are no errors, but it doesn’t process any messages at all. I’ll keep on troubleshooting, but please let me know if you have any ideas.

Thanks @Franky1, that configuration worked. The problem where no messages were processing was unrelated, I’ll do a new post for that one.