prometheus-community / json_exporter

A prometheus exporter which scrapes remote JSON by JSONPath
Apache License 2.0
638 stars 197 forks source link

Trim spaces from values #344

Open vaionicle opened 1 day ago

vaionicle commented 1 day ago

Adding the ability to trim spaces in values.

I got a json response from an Iot device with almost all numeric values contain spaces before or after the value. I trim the spaces to parse them correctly.

{
    "OVERVIEW": {
        "LOCAL_TIME": "Thu, 21 Nov 2024 22:02:09",
        "AKZ": "                                ",
        "OKZ": "                      ",
        "Import_T1": {
            "value": "    13441.23",
            "unit": "kWh"
        },
        "Import_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "Export_T1": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "Export_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "TODAY_T1": {
            "value": "        7.98",
            "unit": "kWh"
        },
        "TODAY_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "THISMONTH_T1": {
            "value": "      296.04",
            "unit": "kWh"
        },
        "THISMONTH_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "P_L1": {
            "value": "0.39",
            "unit": "kW"
        },
        "P_L2": {
            "value": "0.03",
            "unit": "kW"
        },
        "P_L3": {
            "value": "0.03",
            "unit": "kW"
        },
        "P_SUM": {
            "value": "0.45",
            "unit": "kW"
        },
        "VA_SUM": {
            "value": "0.62",
            "unit": "kVA"
        },
        "VARQ1_SUM": {
            "value": "-0.19",
            "unit": "kvar"
        },
        "PF_SUM": {
            "value": "0.727",
            "unit": "     "
        }
    }
}