# Parsing Telegraf output json as input json

**URL:** <https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274>\
**Category:** Telegraf\
**Tags:** telegraf, json\
**Created:** [August 26, 2022, 8:43am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274 "2022-08-26T08:43:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_gronska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/john_gronska/32/9950_2.png) [@john\_gronska](https://community.influxdata.com/u/john_gronska)\
**Post date:** [August 26, 2022, 8:43am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/1 "2022-08-26T08:43:22Z")

</div>

I’m trying to “pipe” JSON between instances of Telegraf.

Data in Telegraf’s [JSON output standard format](https://docs.influxdata.com/telegraf/v1.23/data_formats/output/json/#examples):

```auto
{
    "fields": {
        "field_1": 30,
        "field_2": 4,
        "field_N": 59,
        "n_images": 660
    },
    "name": "my_measurement",
    "tags": {
        "tag_1": "bovik"
    },
    "timestamp": 1458229140
}

```

Given the input config

```auto
  data_format = "json"

```

we get

```auto
{
    "fields": {
        "fields_field_1": 30,
        "fields_field_2": 4,
        "fields_field_N": 59,
        "fields_n_images": 660,
        "timestamp": 1458229140
    },
    "name": "file",
    "tags": {
        "host": "my-computer.local"
    },
    "timestamp": 1661502531
}

```

where the measurement name is lost, all the tags are lost, and the fields are prepended with `fields_`.

Given the input config

```auto
  data_format = "json"
  tag_keys = ["name", "tags_*"]

```

we get

```auto
{
    "fields": {
        "fields_field_1": 30,
        "fields_field_2": 4,
        "fields_field_N": 59,
        "fields_n_images": 660,
        "timestamp": 1458229140
    },
    "name": "file",
    "tags": {
        "host": "my-computer.local",
        "name": "my_measurement",
        "tags_tag_1": "bovik"
    },
    "timestamp": 1661502562
}

```

where the measurement name and tags are kept, but field and tag names are prepended with `tags_` and `fields_`.

Given the input config

```auto
  data_format = "json"
  tag_keys = ["name", "tags_*"]
  [[processors.regex]]
    [[processors.regex.tag_rename]]
      pattern = "^tags_(.+)$"
      replacement = "${1}"
    [[processors.regex.field_rename]]
      pattern = "^fields_(.+)$"
      replacement = "${1}"

```

we get

```auto
{
    "fields": {
        "field_1": 30,
        "field_2": 4,
        "field_N": 59,
        "n_images": 660,
        "timestamp": 1458229140
    },
    "name": "file",
    "tags": {
        "host": "my-computer.local",
        "name": "my_measurement",
        "tag_1": "bovik"
    },
    "timestamp": 1661502609
}

```

which at least resembles the original data (ignoring the extra `timestamp`) and is usable.

Using `json_v2` was even more of a time sink. In the data, `tags` is an object, so I hit [Add dynamic tag set to json\_v2 · Issue #10576 · influxdata/telegraf · GitHub](https://github.com/influxdata/telegraf/issues/10576)

Am I missing something or should not there be an easy “out of the box” way to ingest JSON from another instance of Telegraf, without hard-coding strings and regexes into the config?

---

<div class="post-metadata">

**Author:** ![Jay\_Clifford](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jay_clifford/32/8287_2.png) [@Jay\_Clifford](https://community.influxdata.com/u/Jay_Clifford)\
**Post date:** [August 26, 2022, 9:14am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/2 "2022-08-26T09:14:15Z")

</div>

Hi @john_gronska,  
So in the original JSON parser, you had to specify the string values like so:

```auto
  ## String fields is an array of keys that should be added as string fields.
  json_string_fields = []

```

Personally, for your use case, I would make use of the JSON V2 parser instead:

> **[%%title%% | InfluxData | InfluxData](https://www.influxdata.com/blog/how-parse-json-telegraf-influxdb-cloud/)**
>
> We have made a lot of enhancements to the new JSON parser that can help you easily read in your JSON data into InfluxDB.

Will ingest strings by default and give you more versatility over how you parse the incoming json payload.

---

<div class="post-metadata">

**Author:** ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)\
**Post date:** [August 26, 2022, 10:25am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/3 "2022-08-26T10:25:22Z")

</div>

Even more, why not using telegraf’s native influx format to pipe 1 telegraf to another?

---

<div class="post-metadata">

**Author:** ![john\_gronska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/john_gronska/32/9950_2.png) [@john\_gronska](https://community.influxdata.com/u/john_gronska)\
**Post date:** [August 26, 2022, 10:27am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/4 "2022-08-26T10:27:10Z")

</div>

> [@Jay\_Clifford](#):
>
> Personally, for your use case, I would make use of the JSON V2 parser instead:
> 
> [How to Parse JSON with Telegraf into InfluxDB Cloud | InfluxData](https://www.influxdata.com/blog/how-parse-json-telegraf-influxdb-cloud/)

Thanks for your response. At the bottom of my admittedly long post, I wrote “Using `json_v2` was even more of a time sink. In the data, `tags` is an object, so I hit [Add dynamic tag set to json\_v2 · Issue #10576 · influxdata/telegraf · GitHub](https://github.com/influxdata/telegraf/issues/10576)”. I actually started with `json_v2` and backed down to `json` after not being able to come up with a config that would work for this use case.

---

<div class="post-metadata">

**Author:** ![john\_gronska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/john_gronska/32/9950_2.png) [@john\_gronska](https://community.influxdata.com/u/john_gronska)\
**Post date:** [August 26, 2022, 10:28am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/5 "2022-08-26T10:28:47Z")

</div>

> [@Hipska](#):
>
> Even more, why not using telegraf’s native influx format to pipe 1 telegraf to another?

That makes sense, yes, but they’re connected via MQTT, and other services are potentially on that “message bus” (plus I already have a fleet of devices speaking JSON in the field).

---

<div class="post-metadata">

**Author:** ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)\
**Post date:** [August 26, 2022, 10:31am UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/6 "2022-08-26T10:31:04Z")

</div>

Okay, that wasn’t clear initially. Nevermind what I said then…

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [September 5, 2022, 7:42pm UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/7 "2022-09-05T19:42:39Z")

</div>

Hey @john_gronska,

did you try to use the `xpath` parser with

```nohighlight
  data_format = "xpath_json"

  [[inputs.file.xpath]]
    metric_name = "/name"
    timestamp = "/timestamp"
    timestamp_format = "unix"
    field_selection = "fields/*"
    tag_selection = "tags/*"

```

---

<div class="post-metadata">

**Author:** ![Michael\_Rarela](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/michael_rarela/32/17144_2.png) [@Michael\_Rarela](https://community.influxdata.com/u/Michael_Rarela)\
**Post date:** [May 6, 2025, 9:27pm UTC](https://community.influxdata.com/t/parsing-telegraf-output-json-as-input-json/26274/8 "2025-05-06T21:27:00Z")

</div>

This is related: [Telegraf Dynamic Tag Parsing - Batch Style](https://community.influxdata.com/t/telegraf-dynamic-tag-parsing-batch-style/57186), except an array is used too.
