Hi
I"m trying to use the HTTP Binding to retrieve a JSON feed from a Web API (TFL Bus Arrivals)… However, the JSON response contains a varying number of responses with multiple fields as below…
{
"id": "string",
"operationType": 0,
"vehicleId": "string",
"naptanId": "string",
"stationName": "string",
"lineId": "string",
"lineName": "string",
"platformName": "string",
"direction": "string",
"bearing": "string",
"destinationNaptanId": "string",
"destinationName": "string",
"timestamp": "2019-01-08T22:57:30.530Z",
"timeToStation": 0,
"currentLocation": "string",
"towards": "string",
"expectedArrival": "2019-01-08T22:57:30.530Z",
"timeToLive": "2019-01-08T22:57:30.530Z",
"modeName": "string",
"timing": {
"countdownServerAdjustment": "string",
"source": "2019-01-08T22:57:30.530Z",
"insert": "2019-01-08T22:57:30.530Z",
"read": "2019-01-08T22:57:30.530Z",
"sent": "2019-01-08T22:57:30.530Z",
"received": "2019-01-08T22:57:30.530Z"
}
}
There can be as many as 20 “records” returned from the call to the API.
Is there anyway with the HTTP binding to workout how many records have been returned and populate items with the response? I’ve managed to work out how to pick the fields out of each record with a JSONPath transformation using
JSONPATH($[0].lineName
I’ve currently created 4 sets of items for the fields I need using this method, but if there are less than 4 records in the response i see the following errors
org.openhab.core.transform.TransformationException: Invalid path '$[3].lineName
I’m starting to think that this may not be possible using the HTTP binding and may require coding in it’s own binding to manipulate the JSON response and understand the number of records returned.
The API can be accessed at https://api-radon.tfl.gov.uk/StopPoint/490014270P/Arrivals
Thanks