API suggestions

Hi,

Trying a bit to create an app but I run into an issue with the api.
Does anyone know a good page on the web that explains how to parse out details from a complicated response. In the example below time

{
“Departure”: [
{
“JourneyDetailRef”: {
“ref”: “1|114336|1|1|1032022”
},
“JourneyStatus”: “P”,
“ProductAtStop”: {
“icon”: {
“res”: “prod_gen”
},
“name”: “Länstrafik - Buss Svart”,
“internalName”: “Länstrafik - Buss Svart”,
“displayNumber”: “Svart”,
“num”: “Svart”,
“line”: “Svart”,
“lineId”: “1279521100001”,
“catOut”: “BLT”,
“catIn”: “BLT”,
“catCode”: “7”,
“cls”: “128”,
“catOutS”: “BLT”,
“catOutL”: “Länstrafik - Buss”,
“operatorCode”: “279”,
“operator”: “Västtrafik”,
“admin”: “279___”,
“matchId”: “Svart;5211;255152”
},
“Product”: [
{
“icon”: {
“res”: “prod_gen”
},
“name”: “Länstrafik - Buss Svart”,
“internalName”: “Länstrafik - Buss Svart”,
“displayNumber”: “Svart”,
“num”: “Svart”,
“line”: “Svart”,
“lineId”: “1279521100001”,
“catOut”: “BLT”,
“catIn”: “BLT”,
“catCode”: “7”,
“cls”: “128”,
“catOutS”: “BLT”,
“catOutL”: “Länstrafik - Buss”,
“operatorCode”: “279”,
“operator”: “Västtrafik”,
“admin”: “279___”,
“routeIdxFrom”: 15,
“routeIdxTo”: 29,
“matchId”: “Svart;5211;255152”
}
],
“name”: “Länstrafik - Buss Svart”,
“type”: “ST”,
“stop”: “Kvisljungeby (Göteborg kn)”,
“stopid”: “A=1@O=Kvisljungeby (Göteborg kn)@X=11830299@Y=57754291@U=1@L=740059381@”,
“stopExtId”: “740059381”,
"time": “19:29:00”,
“date”: “2022-03-01”,
“reachable”: true,
“direction”: “Sävedalen Ljungkullen (Partille kn)”,
“directionFlag”: “1”
},
{
“JourneyDetailRef”: {
“ref”: “1|114336|2|1|1032022”
},
“JourneyStatus”: “P”,

Thanks in advance

If that’s a JSON. I don’t know if you missed pasting some of it or not but you can paste the raw json file in something like an online JSON viewer which makes it easier to decipher the nested data.

1 Like

Hi,

Yes it is a json file I did not paste the full since somebody was criticised in another thread for pasting a lot of code.
My goal is to get the different time tags out.
They are when the bus is leaving at my busstop

  • ‘Departure’:[
    1. {
    • ‘JourneyDetailRef’:{
      • ‘ref’:‘1|127806|0|1|2032022’},
    • ‘JourneyStatus’:‘P’,
    • ‘ProductAtStop’:{
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘matchId’:‘Svart;5211;253227’},
    • ‘Product’:[
      1. {
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘routeIdxFrom’:15,
      • ‘routeIdxTo’:29,
      • ‘matchId’:‘Svart;5211;253227’}],
    • ‘name’:‘Länstrafik - Buss Svart’,
    • ‘type’:‘ST’,
    • ‘stop’:‘Kvisljungeby (Göteborg kn)’,
    • ‘stopid’:‘A=1@O=Kvisljungeby (Göteborg kn)@X=11830299@Y=57754291@U=1@L=740059381@’,
    • ‘stopExtId’:‘740059381’,
    • ‘time’:‘18:29:00’,
    • ‘date’:‘2022-03-02’,
    • ‘reachable’:True,
    • ‘direction’:‘Sävedalen Ljungkullen (Partille kn)’,
    • ‘directionFlag’:‘1’},
    1. {
    • ‘JourneyDetailRef’:{
      • ‘ref’:‘1|127806|1|1|2032022’},
    • ‘JourneyStatus’:‘P’,
    • ‘ProductAtStop’:{
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘matchId’:‘Svart;5211;253894’},
    • ‘Product’:[
      1. {
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘routeIdxFrom’:15,
      • ‘routeIdxTo’:29,
      • ‘matchId’:‘Svart;5211;253894’}],
    • ‘name’:‘Länstrafik - Buss Svart’,
    • ‘type’:‘ST’,
    • ‘stop’:‘Kvisljungeby (Göteborg kn)’,
    • ‘stopid’:‘A=1@O=Kvisljungeby (Göteborg kn)@X=11830299@Y=57754291@U=1@L=740059381@’,
    • ‘stopExtId’:‘740059381’,
    • ‘time’:‘18:44:00’,
    • ‘date’:‘2022-03-02’,
    • ‘reachable’:True,
    • ‘direction’:‘Sävedalen Ljungkullen (Partille kn)’,
    • ‘directionFlag’:‘1’},
    1. {
    • ‘JourneyDetailRef’:{
      • ‘ref’:‘1|127806|2|1|2032022’},
    • ‘JourneyStatus’:‘P’,
    • ‘ProductAtStop’:{
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘matchId’:‘Svart;5211;257339’},
    • ‘Product’:[
      1. {
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘routeIdxFrom’:15,
      • ‘routeIdxTo’:29,
      • ‘matchId’:‘Svart;5211;257339’}],
    • ‘name’:‘Länstrafik - Buss Svart’,
    • ‘type’:‘ST’,
    • ‘stop’:‘Kvisljungeby (Göteborg kn)’,
    • ‘stopid’:‘A=1@O=Kvisljungeby (Göteborg kn)@X=11830299@Y=57754291@U=1@L=740059381@’,
    • ‘stopExtId’:‘740059381’,
    • ‘time’:‘18:59:00’,
    • ‘date’:‘2022-03-02’,
    • ‘reachable’:True,
    • ‘direction’:‘Sävedalen Ljungkullen (Partille kn)’,
    • ‘directionFlag’:‘1’},
    1. {
    • ‘JourneyDetailRef’:{
      • ‘ref’:‘1|127839|0|1|2032022’},
    • ‘JourneyStatus’:‘P’,
    • ‘ProductAtStop’:{
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘matchId’:‘Svart;5211;255327’},
    • ‘Product’:[
      1. {
      • ‘icon’:{
        • ‘res’:‘prod_gen’},
      • ‘name’:‘Länstrafik - Buss Svart’,
      • ‘internalName’:‘Länstrafik - Buss Svart’,
      • ‘displayNumber’:‘Svart’,
      • ‘num’:‘Svart’,
      • ‘line’:‘Svart’,
      • ‘lineId’:‘1279521100001’,
      • ‘catOut’:‘BLT’,
      • ‘catIn’:‘BLT’,
      • ‘catCode’:‘7’,
      • ‘cls’:‘128’,
      • ‘catOutS’:‘BLT’,
      • ‘catOutL’:‘Länstrafik - Buss’,
      • ‘operatorCode’:‘279’,
      • ‘operator’:‘Västtrafik’,
      • ‘admin’:‘279___’,
      • ‘routeIdxFrom’:15,
      • ‘routeIdxTo’:29,
      • ‘matchId’:‘Svart;5211;255327’}],
    • ‘name’:‘Länstrafik - Buss Svart’,
    • ‘type’:‘ST’,
    • ‘stop’:‘Kvisljungeby (Göteborg kn)’,
    • ‘stopid’:‘A=1@O=Kvisljungeby (Göteborg kn)@X=11830299@Y=57754291@U=1@L=740059381@’,
    • ‘stopExtId’:‘740059381’,
    • ‘time’:‘19:14:00’,
    • ‘date’:‘2022-03-02’,
    • ‘reachable’:True,
    • ‘direction’:‘Sävedalen Ljungkullen (Partille kn)’,
    • ‘directionFlag’:‘1’}],
  • ‘TechnicalMessages’:{
    • ‘TechnicalMessage’:[
      1. {
      • ‘value’:‘2022-03-02 18:35:54’,
      • ‘key’:‘requestTime’}]},
  • ‘serverVersion’:‘2.23.0.1’,
  • ‘dialectVersion’:‘2.23’,
  • ‘planRtTs’:‘1970-01-01T01:00:00.000+01:00’,
  • ‘requestId’:‘734efkw4g2xhpkcs’

}

I like to use this json viewer. If I’m reading how this one parsed out then it would be something like this.

I mean that is fair. A link would have been better. I was just gonna try testing it out.

But on a basic sense you would have something like

rep = http.get(url)
data = rep.json()["Departure"][1]["ProductAtStop"]

Essentially every indent is like a [name or index] in the json.

1 Like

Hi!
Thanks a lot the code

data = response.json()[“Departure”][1][“time”]

gave the result

18:44:00

Lovley!

Soon getting there

I actually wasn’t sure if I read those indentations right. glad it worked. You can kind of just play around with it and it will error out if it doesn’t like it.

Once you do it a couple of times it’s not too bad.