Help needed processing JSON

mabnz
Thu, 22 Feb 2024 04:35:39 +0000
Telegraf

I’m trying to parse some JSON via mqtt into telegraf (then into influxdb).

The JSON looks like:

{
    "Time": "2024-02-22T17:50:25",
    "INA3221": {
        "Id": "0x40",
        "Voltage": [
            4.048,
            4.896,
            0
        ],
        "Current": [
            0.123,
            0.11,
            0
        ],
        "Power": [
            0.497,
            0.541,
            0
        ]
    },
    "SGP40": {
        "VOC_Raw": 29635,
        "TVOC": 49
    },
    "TempUnit": "C"
}

I’m having trouble parsing the field for Voltage, current and power with multiple values.

What I’d like, is for this to result in an Influx statement along the lines of this, for each value in the array.

Current1=0.126,Power1=0.497,Voltage1=4.048 1708573439000000000
Current2=0.1,Power2=0.541,Voltage2=4.896 1708573439000000000
Current3=0,Power3=0,Voltage3=0 1708573439000000000

Is this possible using either json_v2 or xpath?

3 posts - 2 participants