# Process an array of json data

**URL:** https://community.influxdata.com/t/process-an-array-of-json-data/34964
**Category:** Telegraf
**Tags:** telegraf, mqtt, json
**Created:** [July 15, 2024, 1:38pm UTC](https://community.influxdata.com/t/process-an-array-of-json-data/34964 "2024-07-15T13:38:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Rishav\_Kumar\_Jha](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/rishav_kumar_jha/32/15976_2.png) [@Rishav\_Kumar\_Jha](https://community.influxdata.com/u/Rishav_Kumar_Jha)
#### Post date: [July 15, 2024, 1:38pm UTC](https://community.influxdata.com/t/process-an-array-of-json-data/34964/1 "2024-07-15T13:38:59Z")

</div>

I have setup the “mqtt\_consume” input plugin for my telegraf agent. The configuration is shown below:

```auto
[[inputs.mqtt_consumer]]
      alias = "input_mqtt_consumer_tsesre_node"
      servers = [
        "mqtt://constellation-gateway-emqx.test.svc.cluster.local:1883"
      ]
      topics = [
        "foo/edge/gms/tsesre/postmetrics/true"
      ]
      persistent_session = false
      username = "test"
      password = "1234"
      json_strict = true
      tag_keys = [
        "tags_*"
      ]
      data_format = "json"
      json_name_key = "measurement"
      json_query = "metrics"
      json_string_fields = [
        "fields_error",
        "fields_success"
      ]
      json_time_format = "unix"
      json_time_key = "epochtime"
      json_timezone = "UTC"
      [inputs.mqtt_consumer.tags]
        tags_for_org = "tsesre"
        tags_company = "REPLACE_WITH_COMPANY_NAME"
        tags_node = "REPLACE_WITH_NODE_NAME"
        tags_site = "REPLACE_WITH_SITE_NAME"

```

And here’s the example of my json data which it is getting from the mqtt broker:

```auto
[
  {
    "metrics": [
      {
        "epochtime": 1721039581,
        "fields": {
          "error": "",
          "success": true
        },
        "measurement": "measurement_test",
        "tags": {
          "bucket_name": "test-bucket",
          "destination": "events",
          "host": "dddev08.abc.com"
        }
      },
      {
        "epochtime": 1721039681,
        "fields": {
          "error": "test error",
          "success": false
        },
        "measurement": "measurement_test",
        "tags": {
          "bucket_name": "test-bucket",
          "destination": "testResults",
          "host": "ddddev08.abc.com"
        }
      }
    ]
  }
]

```

With the above configuration it is unable to process the json data.  
What modifications should i make in the configurations?

Thanks

---

<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: [July 15, 2024, 3:13pm UTC](https://community.influxdata.com/t/process-an-array-of-json-data/34964/2 "2024-07-15T15:13:44Z")

</div>

The JSON parser is only good for flat data. I would suggest taking a look at the xpath parser, specifically the last example titled “JSON Line Protocol”: [telegraf/docs/PARSING\_DATA.md at master · influxdata/telegraf · GitHub](https://github.com/influxdata/telegraf/blob/master/docs/PARSING_DATA.md#json-line-protocol) and adapting it to your data.
