# Filtering incomming data with JSON Schema

**URL:** <https://community.influxdata.com/t/filtering-incomming-data-with-json-schema/33001>\
**Category:** Telegraf\
**Tags:** schema, python, json\
**Created:** [January 29, 2024, 8:07pm UTC](https://community.influxdata.com/t/filtering-incomming-data-with-json-schema/33001 "2024-01-29T20:07:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bletvaska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/bletvaska/32/15004_2.png) [@bletvaska](https://community.influxdata.com/u/bletvaska)\
**Post date:** [January 29, 2024, 8:07pm UTC](https://community.influxdata.com/t/filtering-incomming-data-with-json-schema/33001/1 "2024-01-29T20:07:13Z")

</div>

hello

i am bit new to telegraf. till now i used it mostly for collecting system metrics.

currently i am facing following problem: from several resources/devices i am collecting measurements in form of JSON data. these data are produced by sensors and send as JSON documents over mqtt protocol like this:

```auto
{
   "battery":100,
   "ts":1706550016,
   "temperature":24.4
}

```

because those data are generated by students, i need to validate them - best way is with json schema. so what i need ideally is:

- to write own validator in python (there will be more different measurements and related JSON documents)
- if such JSON document fails the validation, it will be not passed further
- if the input document is valid, i would like to convert it to influx line protocol by my own (the result will be composition of mqtt topic and mqtt message) and with output plugin i will write it to influxdb.

so the flow looks like:

inputs:mqtt\_consumer → my python validator → outputs:influxdb\_v2

is it possible to do something like this with telegraf or do i need to write my own script? and what is it then? is it input plugin? processor? can you point me, how to do that?

thanks for any help

mirek

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [January 29, 2024, 8:59pm UTC](https://community.influxdata.com/t/filtering-incomming-data-with-json-schema/33001/2 "2024-01-29T20:59:03Z")

</div>

Hello @bletvaska,  
Yes absolutely. You can use the execd processor plugin to do that.  
Here’s an example repo:

> **[GitHub - InfluxCommunity/tg-brew-anomaly](https://github.com/InfluxCommunity/tg-brew-anomaly)**
>
> Contribute to InfluxCommunity/tg-brew-anomaly development by creating an account on GitHub.

```auto
# A simple processor. It reads stdin and writes it to stdout.
import sys

def main():
   for line in sys.stdin:
       print(line.rstrip())
       sys.stdout.flush()

if __name__ == ' __main__':
   main()

```

And the telegraf config would look like:

```auto
[[processors.execd]]
  command = ["python", "./processors/myscript.py"]

```

> <https://github.com/influxdata/telegraf/blob/master/plugins/processors/execd/README.md>

Let me know if that helps.

---

<div class="post-metadata">

**Author:** ![bletvaska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/bletvaska/32/15004_2.png) [@bletvaska](https://community.influxdata.com/u/bletvaska)\
**Post date:** [January 29, 2024, 9:19pm UTC](https://community.influxdata.com/t/filtering-incomming-data-with-json-schema/33001/3 "2024-01-29T21:19:05Z")

</div>

ahoj

thanks for the point. i found it few minutes ago in telegraf basics training, so i am completely in 🙂

mirek
