# Help transforming json document for output to InfluxDB

**URL:** https://discuss.elastic.co/t/help-transforming-json-document-for-output-to-influxdb/229351
**Category:** Logstash
**Created:** [April 22, 2020, 8:50pm UTC](https://discuss.elastic.co/t/help-transforming-json-document-for-output-to-influxdb/229351 "2020-04-22T20:50:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![john.houghton](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@john.houghton](https://discuss.elastic.co/u/john.houghton)
#### Post date: [April 22, 2020, 8:50pm UTC](https://discuss.elastic.co/t/help-transforming-json-document-for-output-to-influxdb/229351/1 "2020-04-22T20:50:05Z")

</div>

From an application, we generate well-formed json responses into a text file (read: structured output from Telegraf for InfluxDB, formatted in json), e.g.

```auto
{"tags":{"tag_1":"tag_1_value","tag_2":"tag_2_value"},"fields":{"field_1":31,"field_2":"two words"},"name":"test_meas","timestamp":1458229140000}

```

...parsed with **jq** for readability here:

```auto
{
  "tags": {
    "tag_1": "tag_1_value",
    "tag_2": "tag_2_value"
  },
  "fields": {
    "field_1": 31,
    "field_2": "two words"
  },
  "name": "test_meas",
  "timestamp": 1458229140000
}

```

Filebeat picks up these text files and passes them to Logstash for enrichment and ultimately output into InfluxDB.

My goal is to have many different metrics use the same Logstash code, without having to manually code Logstash for each different metric being output.

The inbound json documents is already defined with both the structure and the data that will go into InfluxDB.

So far, I have used a json output plugin to parse the field "message" into a field "payload". (I did this so I don't have to deal with all of the extraneous data that comes with the document, e.g. host, agent, log, ecs, @version, etc. and to future proof it from other new fields.) So, as I see it, use\_event\_fields\_for\_data\_points is not appropriate here since I am only using a subset of the fields in the document.

But this is where I get stuck. As I understand it, I need InfluxDB output plugin's "data\_points" to have ALL of the tags and fields. And "send\_as\_tags" needs to have an to enumerate list of the tags. Lastly, I need to coerce values that should be integers for consistency.

QUESTIONS

1. Is there any elegant way to translate the payload's field and tag nodes into the **hash** that the data\_points expects?
2. Is there any elegant way to translate the payload's tag node to generate the **array** that send\_as\_tags expects?

Still to be resolved: how to enumerate a set of "coerce\_values" keys for those fields that end in "i" to be integers (bonus credit)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 20, 2020, 8:50pm UTC](https://discuss.elastic.co/t/help-transforming-json-document-for-output-to-influxdb/229351/2 "2020-05-20T20:50:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
