1
0
Fork 0
telegraf/plugins/processors/starlark/testdata/json.star
Daniel Baumann 4978089aab
Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-05-24 07:26:29 +02:00

18 lines
569 B
Text

# Example of parsing json out of a field and modifying the metric with it.
# this is great to use in conjunction with the value parser.
#
# Example Input:
# json value="{\"label\": \"hero\", \"count\": 14}" 1465839830100400201
#
# Example Output:
# json,label=hero count=14i 1465839830100400201
load("json.star", "json")
# loads json.encode(), json.decode(), json.indent()
def apply(metric):
j = json.decode(metric.fields.get('value'))
metric.fields.pop('value')
metric.tags["label"] = j["label"]
metric.fields["count"] = j["count"]
return metric