JSON Values From Webhook enclosed in square brackets

Hi

I have a webhook that receives the following content from a tracking device.

[{‘BatteryCurrent’: 0, ‘BatteryVoltage’: 4.123, ‘ChannelId’: 1225350, ‘CodecId’: 142, ‘DeviceId’: 5938473, ‘DeviceName’: ‘Robs Car’, ‘DeviceTypeId’: 2334, ‘EngineIgnitionStatus’: False, ‘EventPriorityEnum’: 0, ‘ExternalPowersourceVoltage’: 19.462, ‘GnssStateEnum’: 1, ‘GnssStatus’: True, ‘GsmMcc’: 234, ‘GsmMnc’: 15, ‘GsmOperatorCode’: ‘23415’, ‘GsmSignalLevel’: 60, ‘Ident’: ‘864636065799927’, ‘MovementStatus’: False, ‘Peer’: ‘85.255.333.333:56063’, ‘PositionAltitude’: 59, ‘PositionDirection’: 15, ‘PositionHdop’: 1.2, ‘PositionLatitude’: 51.73748, ‘PositionLongitude’: -1.015737, ‘PositionPdop’: 2, ‘PositionSatellites’: 9, ‘PositionSpeed’: 0, ‘PositionValid’: True, ‘ProtocolId’: 14, ‘ServerTimestamp’: 1728586733.704578, ‘SleepModeEnum’: 0, ‘Timestamp’: 1728586668, ‘VehicleMileage’: 29.627}]

The issue I have is that the JSON is enclosed in the square brackets so using the trigger.json in the automation doesn’t work to retrieve the values in the automations. If I remove the brackets and send it using Postman the automation works.

description: ""
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
    local_only: false
    webhook_id: "-2spsF8QBr-Kxxxxxxxxx"
conditions: []
actions:
  - action: notify.o365_email_hotmail
    metadata: {}
    data:
      title: Car Tracker
      target: [email protected]
      message: >
        JSON Received:  {{ trigger.json }} <br><br> Latitude: {{
        trigger.json.PositionLatitude }} <br> Longitude: {{
        trigger.json.PositionLongitude }}
  - action: device_tracker.see
    data:
      dev_id: robscar
      gps:{{trigger.json.PositionLatitude }} <br> Longitude:
        "[object Object]": null
mode: single

I have searched for other examples with the likes of value_json[0] but I don’t seem to be able to retrieve the values from the JSON data.

Can anyone explain the correct format to retrieve each of the values from the JSON when it is enclosed in the square brackets?

Thanks

The square brackets are a list with one element (your json). List indexes start counting at 0. So to access that first element (your json):

      message: >
        Latitude: {{ trigger.json[0].PositionLatitude }} <br> 
        Longitude: {{ trigger.json[0].PositionLongitude }}

Perfect!!

Knew it’d be simple, thanks for the help all working as expected now.

1 Like