Parsing JSON data into multiple entries

tberton
Sat, 15 Mar 2025 07:19:31 +0000
Telegraf

Hi,
I am trying to create a Telegraf config to parse the following JSON data into multiple entries:

{
    "IMEI": "5679789121",
    "Model": "X64B1",
    "temperature": 18.8,
    "humidity": 46.4,
    "interrupt": 0,
    "interrupt_level": 0,
    "battery": 3.57,
    "signal": 14,
    "1": [
        18.5,
        43.3,
        "2025/03/13 16:36:11"
    ],
    "2": [
        18.4,
        43.6,
        "2025/03/13 16:21:11"
    ],
    "3": [
        17.8,
        43.8,
        "2025/03/13 16:06:11"
    ],
    "4": [
        17.6,
        43.5,
        "2025/03/13 15:51:11"
    ],
    "5": [
        17.5,
        43.5,
        "2025/03/13 15:36:11"
    ],
    "6": [
        17.8,
        43.9,
        "2025/03/13 15:21:11"
    ],
    "7": [
        17.7,
        44.5,
        "2025/03/13 15:06:11"
    ],
    "8": [
        17.7,
        44.6,
        "2025/03/13 14:51:11"
    ]
}

This is data being captured from a sensor device. It sends the current information (temperature, humidity, battery, signal, etc.), but also the stored information (in this case 1-8). The device uploads once every x time, but captures every 14 minutes.
I would like to store the current information, but also the stored information. The first field in the array is temperature, next humidity, and at last the timestamp when captured.

I think what I am looking for is something like this:

time="2025/03/13 16:36:11",humidity=43.3,temperature=18.5

time="2025/03/13 16:21:11",humidity=43.6,temperature=18.4

time="2025/03/13 16:06:11",humidity=43.8,temperature=17.8

time="2025/03/13 15:51:11",humidity=43.5,temperature=17.6

and so on.
Ideally the time should become the data timestamp.

I’ve looked into both json_v2 and xpath input. But got stuck on both, without any usefull result.

2 posts - 2 participants