Since you have access to Python, I suggest you use Python since it’s a tool well suited for your task. You can review the solution presented below in it’s entirety here: trinket.io
Your data
This is how I assume your data is structured in the server of the API. Note that I have omitted most attributes for sake of clarity. Also note that I’ve added few entries to show that the solution works for multiple entries as well.
api_data = {
"ac": # There could be more top-level keys
[
# Each flight is a dictionary. All such flights are contained in one list
{"posttime": "1596223612488", "icao": "AE5E06", "type": ""},
{"posttime": "1596223613939", "icao": "AB63BC", "type": "ULAC"},
{"posttime": "1596223613940", "icao": "AB63BD", "type": "ULAC"},
{"posttime": "1596223612489", "icao": "AE5E07", "type": ""},
{"posttime": "1596223613941", "icao": "AB63BE", "type": "ULAC"},
]
}
Converting the above to a JSON string and printing it:
import json
JSON = json.dumps(api_data)
print(JSON)
results in the following string, which should match the string you receive from the api:
{"ac": [{"posttime": "1596223612488", "type": "", "icao": "AE5E06"}, {"posttime": "1596223613939", "type": "ULAC", "icao": "AB63BC"}, {"posttime": "1596223613940", "type": "ULAC", "icao": "AB63BD"}, {"posttime": "1596223612489", "type": "", "icao": "AE5E07"}, {"posttime": "1596223613941", "type": "ULAC", "icao": "AB63BE"}]}
The solution
First, we convert the JSON string to python objects:
data = json.loads(JSON)
This results in the same data structure as the variable api_data
above.
The next step is to extract the planes which match your criterion, i.e. the type should be
“ULAC”:
def criterion(plane):
return p["type"].lower() == "ulac"
selected_planes = [p for p in data["ac"] if criterion(p)]
Note that I isolated the criterion in a function. This way, it’s easy for youth modify the criterion as you see fit. Also note that I compared the type to lowercase “ulac”, which makes the comparison more robust.
Finally, we print the selected planes:
print("Selected the following {} planes:\n".format(len(selected_planes)))
print(selected_planes)
The printout of the above is:
Selected the following 3 planes:
[{'posttime': '1596223613939', 'type': 'ULAC', 'icao': 'AB63BC'}, {'posttime': '1596223613940', 'type': 'ULAC', 'icao': 'AB63BD'}, {'posttime': '1596223613941', 'type': 'ULAC', 'icao': 'AB63BE'}]
i.e. only the planes with type “ULAC”.