Maintaining a fixed order in a JSON DAT table from a live API output

Through python, I have implemented a FlightRadar API in TouchDesigner. I’m focusing on creating a London map with the dots representing the live flights with the code being ran every three seconds and updating the flight info

Regarding the python code, it gives me JSON output that looks like this - {
“IB3171”: [
{
“latitude”: 51.184,
“longitude”: -1.1064,
“id”: “34ac716b”,
“icao_24bit”: “346303”,
“heading”: 208,
“altitude”: 4625,
“ground_speed”: 553,
“squawk”: “”,
“aircraft_code”: “A20N”,
“registration”: “EC-NER”,
“time”: 1712508288,
“origin_airport_iata”: “LHR”,
“destination_airport_iata”: “MAD”,
“number”: “IB3171”,
“airline_iata”: “IB”,
“on_ground”: 0,
“vertical_speed”: 2176,
“callsign”: “IBE31RL”,
“airline_icao”: “IBE”
}
],
“BA269”: [
{
“latitude”: 51.6421,
“longitude”: -0.6908,
“id”: “34ac69c5”,
“icao_24bit”: “406B22”,
“heading”: 355,
“altitude”: 2537,
“ground_speed”: 563,
“squawk”: “”,
“aircraft_code”: “A388”,
“registration”: “G-XLEI”,
“time”: 1712508290,
“origin_airport_iata”: “LHR”,
“destination_airport_iata”: “LAX”,
“number”: “BA269”,
“airline_iata”: “BA”,
“on_ground”: 0,
“vertical_speed”: 2624,
“callsign”: “BAW7J”,
“airline_icao”: “BAW”
}

From it, I use two JSON DAT operators to filter out the latitude and longitude from all the flights within London. By using the DAT to CHOP to convert the values to signals, they are then used as X and Y values for the instancing of the geometry COMP in the translate OP section, used for the circle SOP so all the flights are shown on the map.

Yay! So what’s the issue then?

Seeing how I want a smooth transition of the flights moving on the map by using the filter CHOP, I’ve ran into this problem where the dots would randomly fade into different positions as seen in the attached GIF. I found that the issue was from the JSON output. Seeing how the flights will have changed in order depending on if they have left London or departed, the output will shift in order.

2024-04-0717-46-18-ezgif.com-crop

What my question is how can I maintain a fixed order of the flights in the DAT table? lets say if the flight is on the fourth column, I want it to stay there so it doesn’t mess with the instancing for the GEO comp to allow smooth transitions with the filter CHOP.

Any help would be greatly appreciated!

What you need to do is use the “id” in the JSON as the identifier for the flight instead of which column it’s on.

I’m not entirely sure that I follow with what you’re saying. Would you mind elaborating? Are you saying to use the id in the JSONpath filter section instead, or to change the formatting of the table?

I can’t see really what’s going on in your video, but the JSON objects you’re getting from the API have flight numbers and also ids as part of the data. You need to use those to keep track of individual flights if the API doesn’t guarantee consistent ordering.

1 Like