How to get and extract json objects and properties?

Hi Try to extract “header” from the response. Looked at instrucs
See any problems with this example of the response and the image of my block?

PS: The result i get is “NULL”
If i only use the response as is I get all data nice and fine… But i only want “header”

Click to view entire JSON response
[
 {
   "version": 2,
   "created": "2024-01-11T09:25:52.163+01:00",
   "deviation_case_id": 550856,
   "publish": {
     "from": "2024-01-11T09:25:52.153+01:00",
     "upto": "2024-01-16T23:30:00.000+01:00"
   },
   "priority": {
     "importance_level": 2,
     "influence_level": 3,
     "urgency_level": 1
   },
   "message_variants": [
     {
       "header": "Avstängd hiss vid Odenplan",
       "details": "Hissen vid Odenplan, entrén mot Västmannagatan/Karlbergsvägen, är avstängd på grund av tekniskt fel. Resenärer i behov av hiss hänvisas till den andra entrén mot Odenplan/bussar.\n\nVi saknar prognos på när hissen åter kan tas i bruk.\n\n",
       "scope_alias": "Tunnelbanans gröna linje 17, 18, 19",
       "language": "sv"
     }
   ],
   "scope": {
     "stop_areas": [
       {
         "id": 1131,
         "name": "Odenplan",
         "type": "METROSTN",
         "transport_authority": 1
       }
     ],
     "lines": [
       {
         "id": 18,
         "transport_authority": 1,
         "designation": "18",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       },
       {
         "id": 19,
         "transport_authority": 1,
         "designation": "19",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       },
       {
         "id": 17,
         "transport_authority": 1,
         "designation": "17",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       }
     ]
   }
 },
 {
   "version": 1,
   "created": "2024-01-14T09:32:11.557+01:00",
   "deviation_case_id": 792963,
   "publish": {
     "from": "2024-01-14T09:32:11.540+01:00",
     "upto": "2024-01-21T10:29:00.000+01:00"
   },
   "priority": {
     "importance_level": 2,
     "influence_level": 3,
     "urgency_level": 1
   },
   "message_variants": [
     {
       "header": "Avstängd hiss vid Skanstull",
       "details": "Skanstull: En hiss mot gatuplan, entrén mot Ringvägen, är avstängd på grund av tekniskt fel. Resenärer hänvisas till andra hissar.\n\nVi saknar prognos på när hissen åter kan tas i bruk.\n\n",
       "scope_alias": "Tunnelbanans gröna linje 17, 18, 19",
       "language": "sv"
     }
   ],
   "scope": {
     "stop_areas": [
       {
         "id": 1521,
         "name": "Skanstull",
         "type": "METROSTN",
         "transport_authority": 1
       }
     ],
     "lines": [
       {
         "id": 19,
         "transport_authority": 1,
         "designation": "19",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       },
       {
         "id": 18,
         "transport_authority": 1,
         "designation": "18",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       },
       {
         "id": 17,
         "transport_authority": 1,
         "designation": "17",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       }
     ]
   }
 },
 {
   "version": 1,
   "created": "2024-01-11T20:43:04.277+01:00",
   "deviation_case_id": 751187,
   "publish": {
     "from": "2024-01-11T20:43:04.270+01:00",
     "upto": "2024-01-18T22:00:00.000+01:00"
   },
   "priority": {
     "importance_level": 2,
     "influence_level": 3,
     "urgency_level": 1
   },
   "message_variants": [
     {
       "header": "Avstängd hiss vid Vällingby",
       "details": "Hissen till plattformen mot Hässelby strand vid Vällingby, entrén mot Vällingby torg, är avstängd på grund av tekniskt fel. Resenärer i behov av hiss hänvisas till den andra entrén mot Bräckegatan.\n\nVi saknar prognos på när hissen åter kan tas i bruk.\n\n",
       "scope_alias": "Tunnelbanans gröna linje 19",
       "language": "sv"
     }
   ],
   "scope": {
     "stop_areas": [
       {
         "id": 1301,
         "name": "Vällingby",
         "type": "METROSTN",
         "transport_authority": 1
       }
     ],
     "lines": [
       {
         "id": 19,
         "transport_authority": 1,
         "designation": "19",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       }
     ]
   }
 },
 {
   "version": 2,
   "created": "2024-01-14T08:52:44.193+01:00",
   "deviation_case_id": 792452,
   "publish": {
     "from": "2024-01-14T08:52:44.180+01:00",
     "upto": "2024-01-21T09:45:00.000+01:00"
   },
   "priority": {
     "importance_level": 2,
     "influence_level": 3,
     "urgency_level": 1
   },
   "message_variants": [
     {
       "header": "Avstängd hiss vid Gullmarsplan",
       "details": "Hissen vid Gullmarsplan, mot plattformen till Skarpnäck, Farsta strand och Hagsätra, är avstängd på grund av tekniskt fel. Hänvisning till hissen mot plattformen till Hässelby strand.\n\nVi saknar prognos på när hissen åter kan tas i bruk.\n\n",
       "scope_alias": "Tunnelbanans gröna linje 17, 18, 19",
       "language": "sv"
     }
   ],
   "scope": {
     "stop_areas": [
       {
         "id": 1551,
         "name": "Gullmarsplan",
         "type": "METROSTN",
         "transport_authority": 1
       }
     ],
     "lines": [
       {
         "id": 19,
         "transport_authority": 1,
         "designation": "19",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       },
       {
         "id": 17,
         "transport_authority": 1,
         "designation": "17",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       },
       {
         "id": 18,
         "transport_authority": 1,
         "designation": "18",
         "transport_mode": "METRO",
         "name": "Gröna linjen",
         "group_of_lines": "tunnelbanans gröna linje"
       }
     ]
   }
 },
 {
   "version": 1,
   "created": "2024-01-13T09:04:35.223+01:00",
   "deviation_case_id": 779225,
   "publish": {
     "from": "2024-01-13T09:04:35.210+01:00",
     "upto": "2024-01-20T09:58:00.000+01:00"
   },
   "priority": {
     "importance_level": 2,
     "influence_level": 3,
     "urgency_level": 1
   },
   "message_variants": [
     {
       "header": "Avstängd hiss vid Johannelund",
       "details": "Hissen vid Johannelund, mellan gatuplan och biljetthallen, är avstängd på grund av tekniskt fel. Resenärer i behov av hiss hänvisas till angränsande stationer eller tillgänglighetsgarantin. \n\nVi saknar prognos på när hissen åter kan tas i bruk.\n",
       "scope_alias": "Tunnelbanans gröna linje 17, 18, 19",
       "language": "sv"
     }
   ],


you need to understand that your response is an array of JSON objects.
so you need to grab reference the first object out of that array.
then access that first items message_variants property
BUT message_variants is an array of JSON objects (a nested JSON array)
so, you need to grab. reference to the first message_variants object from that array

now you can grab the header from the header from the first message_variant from the first object in the array of objects that come from the api response
check out page 2 in this project

1 Like

OK Clear thanks alot -
You are having “lists” in the blocks as well… Why is that? (Just asking as i cant try it out myself for a few hours… )

Hello @jared

This img shoudl show a copy of your example but still get NULL as reply.
Checked also to set text_input1 text to “response” just to see i get data in…And i do…
Do you see eny erors?

you need to get object from json. not generate JSON from object

:wink:

Just realised… :smiley: now to the millionaire question. THANKS…
How do i collect two properties Details and Headers and potentially others
Ill try and come back if i get stuck…

I better ask directly - Because i also need to get several
Header/Details information from the same response…
I cant logically see how to even try - Except text “replace”

well, given that jsonResponse is an array and so is message_variants (for each item in the json response)

you’d loop through them both and amalgamate a running list of everything, i’d suppose. really depends on what you need BUT it’s def going to involve looping

@stefansladdeneng1 :point_up_2: :point_up_2: :point_up_2: this is just 1 approach, though fairly straightforward to execute it may not cover all use cases.

you loop through the main item
each sub item has an array and you loop through that too

Hmmm cant figure out the loop to exstract several ”Headers” and ”Details” from a long api response. Any idea?

@jared offered blocks to get the “header” property from each array/list item. Did that work for you? If so, just swap out “details” for “header” to get that property.

If it didn’t work, can you post a screenshot of your blocks?

Hello Tatiang
Iff you mean Jareds example yes it worked but only the first header and details…
What about the secon and thirrd etc??

Sorryy… mustave been a delay in jareds reply
As i did not see it. Ill try again

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.