Malformed StopPoint Json file from TFL Server

I am developing a TFL app in Android and currently retrieving Bus and Naptan Station information.

I am trying to retrieve information for Stop point stations and their naptanId details. Although I get a 200 Ok code and required data, The data files cannot receive the data in the required format because there is contention with the Json format. Whenever the program encounters an end of object or Array, block followed by “Status” True, the download failed with:
expected BEGIN_OBJECT but was BOOLEAN at line 1 column 3944 path $.status**.

Why is there a live Boolean status field and is there a workaround for this?

Retrofit call and resulting data and error below.

https://api.tfl.gov.uk/Stoppoint/490G00003083

“lineGroup”:[{"$type":“Tfl.Api.Presentation.Entities.LineGroup, Tfl.Api.Presentation.Entities”,“naptanIdReference”:“490003083G”,“stationAtcoCode”:“490G00003083”,“lineIdentifier”:[“207”,“218”,“266”,“440”,“607”,“70”,“e3”,“n11”,“n207”,“n266”,“n7”]}],“lineModeGroups”:[{"$type":“Tfl.Api.Presentation.Entities.LineModeGroup, Tfl.Api.Presentation.Entities”,“modeName”:“bus”,“lineIdentifier”:[“207”,“218”,“266”,“440”,“607”,“70”,“e3”,“n11”,“n207”,“n266”,“n7” ]}],“status”:true, “id”:“490003083G”,“commonName”:“Acton Old Town Hall”,“placeType”:“StopPoint”,“additionalProperties”:[{"$type":“Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,“category”:“Direction”,“key”:“CompassPoint”,“sourceSystemKey”:“Naptan490”,“value”:“W”},{"$type":“Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,“category”:“Direction”,“key”:“Towards”,“sourceSystemKey”:“CountDown”,“value”:“Ealing Broadway or North Acton”}],“children”:[],“lat”:51.5067,“lon”:-0.268912},{"$type":“Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,“naptanId”:“490003088L”,“indicator”:“Stop L”,“stopLetter”:“L”,“modes”:[“bus”],“icsCode”:“1003083”,“stopType”:“NaptanPublicBusCoachTram”,“stationNaptan”:“490G00003083”,“lines”:[],“lineGroup”:[],“lineModeGroups”: *[],status":true ,“id”:“490003088L”,“commonName”:“Acton Old Town Hall”,“placeType”:“StopPoint”,“additionalProperties”:[{"$type":“Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,“category”:“Direction”,“key”:“CompassPoint”,“sourceSystemKey”:“Naptan490”,“value”:“N”}],“children”:[],“lat”:51.506284,“lon”:-0.26815}],“lat”:51.5067,“lon”:-0.268912}

<-- END HTTP (13288-byte body)

V/transport_for_london: NetworkBoundaryCallback: onFetchFailed()

V/transport_for_london: NetworkBoundaryCallback: response.errorMessage java.lang.IllegalStateException: **expected BEGIN_OBJECT but was BOOLEAN at line 1 column 3944 path $.status

Json File.

{
“$type”: “Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,
“naptanId”: “490G00003083”,
“modes”: [
“bus”
],
“icsCode”: “1003083”,
“stopType”: “NaptanOnstreetBusCoachStopCluster”,
“stationNaptan”: “490G00003083”,
“lines”: [
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “207”,
“name”: “207”,
“uri”: “/Line/207”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “218”,
“name”: “218”,
“uri”: “/Line/218”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “266”,
“name”: “266”,
“uri”: “/Line/266”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “427”,
“name”: “427”,
“uri”: “/Line/427”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “440”,
“name”: “440”,
“uri”: “/Line/440”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “607”,
“name”: “607”,
“uri”: “/Line/607”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “70”,
“name”: “70”,
“uri”: “/Line/70”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “e3”,
“name”: “E3”,
“uri”: “/Line/e3”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n11”,
“name”: “N11”,
“uri”: “/Line/n11”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n207”,
“name”: “N207”,
“uri”: “/Line/n207”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n266”,
“name”: “N266”,
“uri”: “/Line/n266”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n7”,
“name”: “N7”,
“uri”: “/Line/n7”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
}
],
“lineGroup”: [
{
“$type”: “Tfl.Api.Presentation.Entities.LineGroup, Tfl.Api.Presentation.Entities”,
“naptanIdReference”: “490003083F”,
“stationAtcoCode”: “490G00003083”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
},
{
“$type”: “Tfl.Api.Presentation.Entities.LineGroup, Tfl.Api.Presentation.Entities”,
“naptanIdReference”: “490003083G”,
“stationAtcoCode”: “490G00003083”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“427”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
}
],
“lineModeGroups”: [
{
“$type”: “Tfl.Api.Presentation.Entities.LineModeGroup, Tfl.Api.Presentation.Entities”,
“modeName”: “bus”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“427”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
}
** ],**
** "status": true,**
“id”: “490G00003083”,
“commonName”: “Acton Old Town Hall”,
“placeType”: “StopPoint”,
“additionalProperties”: [],
“children”: [
{
“$type”: “Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,
“naptanId”: “490003083F”,
“indicator”: “Stop F”,
“stopLetter”: “F”,
“modes”: [
“bus”
],
“icsCode”: “1003083”,
“stopType”: “NaptanPublicBusCoachTram”,
“stationNaptan”: “490G00003083”,
“lines”: [
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “207”,
“name”: “207”,
“uri”: “/Line/207”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “218”,
“name”: “218”,
“uri”: “/Line/218”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “266”,
“name”: “266”,
“uri”: “/Line/266”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “440”,
“name”: “440”,
“uri”: “/Line/440”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “607”,
“name”: “607”,
“uri”: “/Line/607”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “70”,
“name”: “70”,
“uri”: “/Line/70”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “e3”,
“name”: “E3”,
“uri”: “/Line/e3”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n11”,
“name”: “N11”,
“uri”: “/Line/n11”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n207”,
“name”: “N207”,
“uri”: “/Line/n207”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n266”,
“name”: “N266”,
“uri”: “/Line/n266”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n7”,
“name”: “N7”,
“uri”: “/Line/n7”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
}
],
“lineGroup”: [
{
“$type”: “Tfl.Api.Presentation.Entities.LineGroup, Tfl.Api.Presentation.Entities”,
“naptanIdReference”: “490003083F”,
“stationAtcoCode”: “490G00003083”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
}
],
“lineModeGroups”: [
{
“$type”: “Tfl.Api.Presentation.Entities.LineModeGroup, Tfl.Api.Presentation.Entities”,
“modeName”: “bus”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
}
],
"status": true,
“id”: “490003083F”,
“commonName”: “Acton Old Town Hall”,
“placeType”: “StopPoint”,
“additionalProperties”: [
{
“$type”: “Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,
“category”: “Direction”,
“key”: “CompassPoint”,
“sourceSystemKey”: “Naptan490”,
“value”: “E”
},
{
“$type”: “Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,
“category”: “Direction”,
“key”: “Towards”,
“sourceSystemKey”: “CountDown”,
“value”: “Shepherd’s Bush, Hammersmith, Chiswick or E Acton”
}
],
“children”: [],
“lat”: 51.506747,
“lon”: -0.267253
},
{
“$type”: “Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,
“naptanId”: “490003083G”,
“indicator”: “Stop G”,
“stopLetter”: “G”,
“modes”: [
“bus”
],
“icsCode”: “1003083”,
“stopType”: “NaptanPublicBusCoachTram”,
“stationNaptan”: “490G00003083”,
“lines”: [
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “207”,
“name”: “207”,
“uri”: “/Line/207”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “218”,
“name”: “218”,
“uri”: “/Line/218”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “266”,
“name”: “266”,
“uri”: “/Line/266”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “427”,
“name”: “427”,
“uri”: “/Line/427”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “440”,
“name”: “440”,
“uri”: “/Line/440”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “607”,
“name”: “607”,
“uri”: “/Line/607”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “70”,
“name”: “70”,
“uri”: “/Line/70”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “e3”,
“name”: “E3”,
“uri”: “/Line/e3”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n11”,
“name”: “N11”,
“uri”: “/Line/n11”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n207”,
“name”: “N207”,
“uri”: “/Line/n207”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n266”,
“name”: “N266”,
“uri”: “/Line/n266”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
},
{
“$type”: “Tfl.Api.Presentation.Entities.Identifier, Tfl.Api.Presentation.Entities”,
“id”: “n7”,
“name”: “N7”,
“uri”: “/Line/n7”,
“type”: “Line”,
“crowding”: {
“$type”: “Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities”
},
“routeType”: “Unknown”,
“status”: “Unknown”
}
],
“lineGroup”: [
{
“$type”: “Tfl.Api.Presentation.Entities.LineGroup, Tfl.Api.Presentation.Entities”,
“naptanIdReference”: “490003083G”,
“stationAtcoCode”: “490G00003083”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“427”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
}
],
“lineModeGroups”: [
{
“$type”: “Tfl.Api.Presentation.Entities.LineModeGroup, Tfl.Api.Presentation.Entities”,
“modeName”: “bus”,
“lineIdentifier”: [
“207”,
“218”,
“266”,
“427”,
“440”,
“607”,
“70”,
“e3”,
“n11”,
“n207”,
“n266”,
“n7”
]
}
** ],**
** “status:” true
“id”: “490003083G”,
“commonName”: “Acton Old Town Hall”,
“placeType”: “StopPoint”,
“additionalProperties”: [
{
“$type”: “Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,
“category”: “Direction”,
“key”: “CompassPoint”,
“sourceSystemKey”: “Naptan490”,
“value”: “W”
},
{
“$type”: “Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,
“category”: “Direction”,
“key”: “Towards”,
“sourceSystemKey”: “CountDown”,
“value”: “Ealing Broadway or Chiswick Business Park”
}
],
“children”: [],
“lat”: 51.5067,
“lon”: -0.268912
},
{
“$type”: “Tfl.Api.Presentation.Entities.StopPoint, Tfl.Api.Presentation.Entities”,
“naptanId”: “490003088L”,
“indicator”: “Stop L”,
“stopLetter”: “L”,
“modes”: [
“bus”
],
“icsCode”: “1003083”,
“stopType”: “NaptanPublicBusCoachTram”,
“stationNaptan”: “490G00003083”,
“lines”: [],
“lineGroup”: [],
“lineModeGroups”: [],
“status”: true,
“id”: “490003088L”,
“commonName”: “Acton Old Town Hall”,
“placeType”: “StopPoint”,
“additionalProperties”: [
{
“$type”: “Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities”,
“category”: “Direction”,
“key”: “CompassPoint”,
“sourceSystemKey”: “Naptan490”,
“value”: “N”
}
],
“children”: [],
“lat”: 51.506284,
“lon”: -0.26815
}
],
“lat”: 51.5067,
“lon”: -0.268912
}

@Leo

I think it’s fine to have booleans in JSON format outputs. https://en.wikipedia.org/wiki/JSON#Data_types_and_syntax

I’m guessing the problem is that you are trying to convert it to another data format which doesn’t support the embedded booleans? If so, grab the string and do a regex on it to turn the true and false into strings before converting to the local object type.

@Leo

Just testing this in PHP and it works fine.

 $fileGetContents=file_get_contents("https://api.tfl.gov.uk/Stoppoint/490G00003083");
 $jsonDecode=json_decode($fileGetContents);
 var_dump($jsonDecode); 

image

Hi Brian,
Thanks for your prompt reply, much appreciated.

I understand that Boolean fields can be formed as part of a Json file. Maybe I didn’t explain myself properly. The problem seems to occur when a boolean field comes after an end of object or array block. The Wikipedia example shows a boolean field after a primitive field.
I made no effort to convert the “status: Boolean” field in the data class, which I have attached below.
I am using Kotlin data classes to capture the response.

I’ve trawled the internet to find out how to do a boolean to string conversion in Kotlin (Android) but to no avail. Is there some one on this forum who can give me some advice on this?

Data Class

data class StopPointNaptan (
@SerializedName("’$'type")
val mainType: String,
@SerializedName(“naptanId”)
val naptanStationId: String,
@SerializedName(“modes”)
val modes: List,
@SerializedName(“icsCode”)
val icsCode: String,
@SerializedName(“stopType”)
val stopType: String,
@SerializedName(“stationNaptan”)
val naptanStation: String,
@SerializedName(“lines”)
val lines: List,
@SerializedName(“lineGroup”)
val lineGroup: List,
@SerializedName(“lineModeGroups”)
val lineModeGroups: List,
@SerializedName(“status”)
val status: Boolean,
@SerializedName(“id”)
val id: String,
@SerializedName(“commonName”)
val commonName: String,
@SerializedName(“placeType”)
val placeType: String,
@SerializedName(“additionalProperties”)
val additionalProperties: ArrayList,
@SerializedName(“children”)
val children : List,
@SerializedName(“lat”)
val lat: Double = 0.0,
@SerializedName(“lon”)
val lon: Double = 0.0
)

Hi @Leo

Is the error occurring in your code, or inside a package (e.g. the JSON parser)?

It may be related to handling of true and false as, effectively, unquoted string values in the incoming datastream, as I doubt that Kotlin data classes hold Booleans as literally ‘true’ and ‘false’ internally.

I don’t think that the fact that the previous field happens to be a list is relevant - once you’re past the terminating comma, any following field should be treated separately.

Hi Nick,

I believe the problem is in the Json parser. I am using Google’s Gson parser. The error occurs, as soon as the End HTTP body is reached. I posted the data class that should receive the request result. No further computation or calls to functions/classes are made at this point to suspect coding errors. If there is a coding error, I suspect it could only be within the format of the receiving data class.

<-- END HTTP (13288-byte body)

V/transport_for_london: NetworkBoundaryCallback: onFetchFailed()

V/transport_for_london: NetworkBoundaryCallback: response.errorMessage java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BOOLEAN at line 1 column 3944 path $.status

@ Leo

Just looking though the JSON and it does seem that status can be:

  • true
  • false
  • “Unknown”

Perhaps this is the problem?

The Boolean value is true according to the returned value, which is exactly what is causing me problems. The status “unknown” fields in Lines are String values and contained within objects which are not the cause of the problem.

It is the status true boolean fields following immediately after a closed array object that are causing the failure.

My question is, how to get around this to prevent failures? There is no point refactoring the data class because it is well formed.

I guess you might need to rtfm - https://github.com/google/gson/blob/master/UserGuide.md ?

I’m wondering why you need to use Gson anyway, why not just convert the JSON to an object using…?

            var jsonObj = JSON.parse(httpRequest.responseText);

Hi Brian.
Gson is the standard json parser used in Android, although there are other parsers such as Moshi.
I have not encountered problems with various parsers or json file formats before now.

Thank you and Nick for your help thus far.

I will take this opportunity to examine the Gson document you have provided and try to implement problem resolution going forward.

@Leo

Have you tried

@SerializedName(“status”)
val status:  Lists,

To pick up the possibility of Boolean.true, Boolean.false and “Unknown” ?

Hi Brian,

Unfortunately, the status field is not contained in a list to pickup 3 possible status codes suggested. status “unknown” is always a primitive string contained in the Lines object array.

screen shots attached for clarity.

@Leo

Sorry, we seem to be going around in circle… It seems to me that the “status” field can be one of three things, but your code is set up to accept only two of them.

Perhaps the Gson code internally corrects the field type from Boolean to String when it encounters “Unknown” and then throws an error when it sees a boolean?

Are we back to using a regex to change true and false into “true” and “false” in in the ascii data before it’s poked into Gson?

Hmm good point, I will examine this.

Hi, Brian,

We are probably going around in circles, simply because I am not explaining my self properly, and showing you segments of data classes that are confusing.

The **Parent (**outer most) object and Children object array have the same data fields
which contain the status boolean, which as you quite rightly stated could contain true or false.

Parent and Children

The Lines object array contains the status “unknown” string fields, which do not appear any where else in the json file. I have actually catered for this in the Lines data class object, so my code is set up for 3 data types not 2.

The Lines, LineGroup and LineModeGroups object arrays are then incorporated in the Parent and Children objects as you will see with the above data class snippet screen shot.

Lines Json and data class

I am examining the point you made about the parser possibly throwing a wobbly, when it encounters a boolean value immediately after parsing the “unknown” string in the Lines object array.

I also do not want to move away from the fact that the error is implying the parser is expecting the beginning of a new object (after the LineModesGroups object array), and not the incorrect data format in the status field.

I hope I have given you more clarity.

Thank you for your cooperation in this matter, it is much appreciated.

@Leo

It seems to me that your code is exemplary and that you have come to a problem that is not easily solvable by using Google. You wouldn’t be here otherwise. I’m sure you must already know you can use try…catch to get the code to continue execution, but without the data from the server that’s of little use here.

I’ve not written an Android app for ages, but from memory the use of the Gson is necessary in these situations. So, my general thinking about this is:

  • I might try and write code that uses a generic JSON string to Java object so that would bypass the parser. The code would then need to parse the object to see if it populated with the values I would expect.
  • I could use a server to grab the JSON from the TfL API and translate it into a simpler object that Gson wouldn’t error on. You could build this in PHP or Javascript on a server and access it via HTTPS or Node.
  • Use a non-Java based Android dev system like https://reactnative.dev/ and just write it in Javascript, which is much less tight about object definitions and parsing.
  • Getting a bit desperate, but you could convert the JSON to XML and then use an XML library to turn the data into a Java object;

As I general principle, I always look at using a public API as a form of hacking: just never assume in your code that what you will get back will be expected. Someone will add a field, or a extra coding or something you will only see overnight or Christmas Day!

I think that’s why I prefer Web Apps as programming approach: if there a bug in the code, you can eradicate for everyone straight away!

Hi Brian,

After further trouble shooting I have finally been able to confirm the error and cause. It does seem to be caused by a malformed json element. We know what that is already.

Latest Error Message states a "JsonSyntaxException"

The online Gson JsonSyntaxException class description.

I am currently reviewing the 4 suggestions you have made, but as you can imagine, I am not happy about the situation.

Thanks.

1 Like