Filter MQTT nested JSON from SignalK for value_json

Dear all, I’m trying to link SignalK information coming from my boat to my homeassistant. I have managed to send selected signalk JSON deltas to my MQTT broker, however, signalk JSON is nested and I cannot manage to extract desired values. I have been trying in the template tester to no avail. This is what i have:

{## Imitate available variables: ##}
{% set value_json = {
  "context": "vessels.urn:mrn:signalk:uuid:1a1fbe92-c128-4564-93fe-4174736872a7",
  "updates": [
    {
      "timestamp": "2023-07-08T04:08:00.710Z",
      "$source": "mqtt.raetara-esp32-bat-monitor",
      "values": [
        {
          "path": "tanks.freshWater.1.currentVolume",
          "value": 139.499985
        }
      ]
    }
  ]
}
%}


The volume is {% set item = value_json.values | selectattr('path', 'eq', 'tanks.freshWater.1.currentVolume') | default %}
{{ item.value | default }}

I want to extract the “value” using a mqtt sensor in homeassitant. However, I need to be able to filter by “path” to make sure I only collect information from the relevant sensor. The current syntax doesn’t throw any error, just a blank result.

Any help would be greatly appreciated. Feel free to suggest another approach if you are familiar with signalk/nodered.

Miquel

Sorted, i finally managed to get the nested syntax correct using https://jsonpath.com/
The use of [] and 0 for empty indents did the trick

{## Imitate available variables: ##}
{% set value_json = {
  "context": "vessels.urn:mrn:signalk:uuid:1a1fbe92-c128-4564-93fe-4174736872a7",
  "updates": [
    {
      "timestamp": "2023-07-08T04:08:00.710Z",
      "$source": "mqtt.raetara-esp32-bat-monitor",
      "values": [
        {
          "path": "tanks.freshWater.1.currentVolume",
          "value": 139.499985
        }
      ]
    }
  ]
}
%}


The volume is {% set item = value_json['updates'].0['values'] | selectattr('path','==','tanks.freshWater.1.currentVolume') | first | default %}
{{ item.value | default }}