JSONPATH doesn't work out for specific MQTT topic

Can somebody help me with the following issue:

Parse MQTT topic “shellies/shellyplug-582BFC/info”:

{
  "wifi_sta": {
    "connected": true,
    "ssid": "dk8pn_rep3",
    "ip": "192.168.1.xxx",
    "rssi": -52
  },
  "cloud": {
    "enabled": false,
    "connected": false
  },
  "mqtt": {
    "connected": true
  },
  "time": "",
  "unixtime": 0,
  "serial": 1,
  "has_update": false,
  "mac": "12345678",
  "cfg_changed_cnt": 0,
  "actions_stats": {
    "skipped": 0
  },
  "relays": [
    {
      "ison": true,
      "has_timer": false,
      "timer_started": 0,
      "timer_duration": 0,
      "timer_remaining": 0,
      "overpower": false,
      "source": "input"
    }
  ],
  "meters": [
    {
      "power": 0,
      "overpower": 0,
      "is_valid": true,
      "timestamp": 0,
      "counters": [
        5,
        0,
        0
      ],
      "total": 0
    }
  ],
  "update": {
    "status": "unknown",
    "has_update": false,
    "new_version": "",
    "old_version": "20230913-113610/v1.14.0-gcb84623"
  },
  "ram_total": 52096,
  "ram_free": 40740,
  "fs_size": 233681,
  "fs_free": 165660,
  "uptime": 2
}

Want to parse the first (0-th) element of the array “counters” which is actually 5. Applied two JSONPATH transformations for trial but both don’t work out.

JSONPATH:$.meters..counters[0]

and

JSONPATH:$.meters[0].counters[0]

Who can give me a hint?

Based on the example you’ve provided, this should be correct. So, there might be something else going on here. I assume you’ve double checked to make sure the JSONPath binding is installed. Are there any log errors or warning? You might need to do some debugging to see what value is actually getting passed to the transform in the first place.

I don’t know if this version should work or not. Using the .. has the possibility to return different types and not necessarily just the value you want, and I have no idea how the binding handles that. But, since the other version should work 100% you don’t need to worry about this one.

Are you applying this in a profile or in a thing / channel configuration?

Thanks so far. It usually works out. I use it in a channel configuration for MQTT. But this is my first case where i have 2 arrays in a row.

I can confirm that JSONPATH:$.meters[0].counters[0] works with the JSON you’ve posted above when run using a script transform action. So if it doesn’t work in your MQTT configuration then the most likely cause is still that the input value for the transform isn’t exactly what you’ve posted above.

The first test I would do is try a more basic JSONpath to see if that is working, e.g. $.mac should return the proper string if this is a string item, or $.serial should return a proper number if this is a number item.

Thank you very much for your support. You have pointed me into the right direction :grinning_face:. After i saw that even the more basic transformations you proposed didn’t work, i changed the MQTT topic name from the name proposed by the Shelly configuration:

shellies/shellyplug-582BFC/info

to the custom defined name:

shellies/shellyplug/info

Then everything works out as expected. The hyphen in the name seems to have caused the problem?