Extract data from each element of an array (for train departures board)

Using the realtimetrains.co.uk API I can get a JSON formatted list of the next 50 (or less) trains to stop at / pass my local station.

So msg.payload.services is an array containing various fields of interest, eg
msg.payload.services[n].locationDetail.origin[0].description (From Birmingham)
msg.payload.services[n].locationDetail.destination[0].description (To Liverpool Lime Street)
msg.payload.services[n].locationDetail.gbttBookedDeparture (Due departure time)
msg.payload.services[n].locationDetail.realtimeDeparture (Expected departure time)
etc.

What is the best way to extract those data from the array and display them on the dashboard as a departures board?

loop through msg.payload.services entries and generate an array of objects containing key/val properties you want displaying and send it to a ui template or a ui table node for display.

e.g. if you loop that data source and generate the below format & drop it into msg.payload

[
    {
        "From": "xxx",
        "To": "yyy",
        "Scheduled Time": "zzz",
    },
    {
        "From": "xxx",
        "To": "yyy",
        "Scheduled Time": "zzz",
    },
]

... then send it to the ui table - pretty much job done.

see info here and search the forum for ui-table (or ui_table) (covered many times)

Sorry for the delay responding. Thanks!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.