# Formatting influx INPUT to specific JSON output containing an array

**URL:** <https://community.influxdata.com/t/formatting-influx-input-to-specific-json-output-containing-an-array/24246>\
**Category:** Telegraf\
**Tags:** json\
**Created:** [March 15, 2022, 7:36pm UTC](https://community.influxdata.com/t/formatting-influx-input-to-specific-json-output-containing-an-array/24246 "2022-03-15T19:36:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnel\_lim](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/arnel_lim/32/15268_2.png) [@arnel\_lim](https://community.influxdata.com/u/arnel_lim)\
**Post date:** [March 15, 2022, 7:36pm UTC](https://community.influxdata.com/t/formatting-influx-input-to-specific-json-output-containing-an-array/24246/1 "2022-03-15T19:36:44Z")

</div>

I’m looking for some advice on how to format an INFLUX input to a particular JSON ouput format containing an array. I’m generating the INFLUX input, so there’s some flexibility there to combine into a single message or leave as multiple.

I presume another option would be to format INPUT as JSON directly. However, the majority of the other data inputs are using INFLUX format.

Expected JSON OUTPUT

```auto
{
“name”: “Stats-XyzUtilization”,
“tags”: {
   “serialnumber”: “AB78CF2FB-1400”
};
“fields”: [
  {
   “min”: 32,
   “max”: 61,
   “avg”: 34,
   “interval”: 10,
   “samplePeriod”:5,
   “xyz”:0
  }
  {
   “min”: 20,
   “max”: 63,
   “avg”: 52,
   “interval”: 10,
   “samplePeriod”:5,
   “xyz”:1
  }
  {
   “min”: 81,
   “max”: 99,
   “avg”: 92,
   “interval”: 10,
   “samplePeriod”:5,
    “xyz”:2
  }
],
   “lastChange”: 1234567890
}

```

Possible Influx INPUT (I’m generating this, so there is flexibility on how this is input into telegraf)

```auto
Stats-XyzUtilization,serialnumber=”AB78CF2FB-1400”,xyz=0 min=32,max=61,avg=34,interval=10,samplePeriod=5 timestamp=1234567890

Stats-XyzUtilization,serialnumber=”AB78CF2FB-1400”,xyz=1 min=20,max=63,avg=52,interval=10,samplePeriod=5 timestamp=1234567890

Stats-XyzUtilization,serialnumber=”AB78CF2FB-1400”,xyz=2 min=81,max=99,avg=92,interval=10,samplePeriod=5 timestamp=1234567890

```

---

<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:** [March 28, 2022, 1:33pm UTC](https://community.influxdata.com/t/formatting-influx-input-to-specific-json-output-containing-an-array/24246/2 "2022-03-28T13:33:43Z")

</div>

Hi!

Taking a look at your Line Protocol input, the only comment I have is that tags, like `serialnumber` and `xyz` are normally strings. Keep that in mind.

As far as your output, what plugin were you planning to use with telegraf as your destination? Is it you just want it to be JSON data? or are you using it to a specific service or tool?

---

<div class="post-metadata">

**Author:** ![arnel\_lim](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/arnel_lim/32/15268_2.png) [@arnel\_lim](https://community.influxdata.com/u/arnel_lim)\
**Post date:** [March 28, 2022, 3:11pm UTC](https://community.influxdata.com/t/formatting-influx-input-to-specific-json-output-containing-an-array/24246/3 "2022-03-28T15:11:54Z")

</div>

For now, tha plan is to use HTTP output plug with JSON data format. I’ve looked at possibly creating a new serializer or adding an option to the batch\_mode for JSON serializer similar to the multimetric option in the Splunk serializer. However, I was hoping for an option that didn’t require code changes to telegraf.
