# Parsing Data From an API into a List of Unknown Size

**URL:** <https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159>\
**Category:** Questions about Thunkable X\
**Tags:** design, beginner, help\
**Created:** [February 28, 2023, 5:21am UTC](https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159 "2023-02-28T05:21:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [February 28, 2023, 5:21am UTC](https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159/1 "2023-02-28T05:21:57Z")

</div>

I am trying to parse information from an API and output the names of each location on the JSON into a listviewer.

I previously asked about how to correctly extract the info and have managed to do so in this thread ([Trying to extract a nested list from a Web API - #8 by ankitn5](https://community.thunkable.com/t/trying-to-extract-a-nested-list-from-a-web-api/2297877/8) ) - thanks so much for your help so far. I figured putting this in a different thread would help others in the future when they are looking for info.

My output response from the API looks like:

```auto
{
	"locations":
	[
		{	
			"cost":1.2,
			"address":"22 Wickham Street, Wickham 2293\n(Entrance on Charles Street)",
			"max_duration":14400,
			"name":"Wickham Terraces",
			"gateway_id":"8642196e-83b5-4e3e-ad9b-60eb5c4f4174"
		},
		{
			"cost":1.2,
			"address":"Address 3",
			"max_duration":14400,
			"name":"Add 3",
			"gateway_id":"8642196e-83b5-4e3e-ad9b-60eb5c4f41755555"
		},
		{
			"cost":1.2,
			"address":"Add 4",
			"max_duration":14400,
			"name":"Add 4",
			"gateway_id":"8642196e-83b5-4e3e-ad9b-6999990eb5c4f4174"
		},
		{
			"cost":1.4,
			"address":"608 Harris Street",
			"max_duration":16400,
			"name":"UTS Tester",
			"gateway_id":"test-2"
		}
	]
}

```

This is an example of the type of JSON rsponse I would receive, but in future it will be x number of locations (instead of the 4 in the example JSON above) provided so I need to figure out how to parse x number of items into the listviewer.

I currently have the following setup on Thunkable. This setup extract the location information into a list of objects (as seen the the solved thread above).

 ![thunk7](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/8/88a14f138782acb59b38f9f80ba51a09f463daf1.png)

And this is what my app looks like when I have run the code.

 ![333933273_178819764882938_1150438690322070840_n](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/5/5541944201ed12465f51a873f32fbe5fd6732ef4.jpeg)

I am able to output the information into a listviewer for a defined number of locations (for example 4), but cannot get it working within a for loop in order to extract the information for any number of locations.

I am hoping someone can show me how to get the for loop working, as I know this should e simple, but I’m just not able to get it.

Cheers

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [February 28, 2023, 5:32am UTC](https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159/2 "2023-02-28T05:32:38Z")

</div>

As an update, I have also tried this process found in the thread below

> [@API results into a List Viewer](https://community.thunkable.com/t/api-results-into-a-list-viewer/51051/5):
>
> @Mark, Thanks for your response. I got it working now! The issue is the 'get object from JSON' block will not connect to the 'for each item j in list' block as depicted here: [Not%20Connecting] However if I save the 'get object from JSON - response' block in a list variable 1st, I am then able to connect the variable to the 'for each item j in list' block. Glad to have this working, and I’ve added my final solution below. Thanks, Darren The following shows how to loop through a JSON List…

And I get the following output on my app. Basically no values pop up in the listviewer.

 ![334238860_2156023574598483_6528638247944174177_n (1)](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/8/2878f561bcdbb3b6963a9bfba19e408c13ac550a.jpeg)

My blocks are shown below

 ![thunk8](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/b/8b4b927ab5a32c8013512cd7f3cf4a8e8b805a1a.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 28, 2023, 5:55am UTC](https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159/3 "2023-02-28T05:55:17Z")

</div>

The key here is that when you use a [for each item] loop, you are not using an integer index (1, 2, 3, etc.). You are actually getting an item from the list which in this case is an object, therefore j is an object. So you can’t use j as your item # for your [in list \_\_\_ get #] block.

Here’s how this should be set up:

 ![Screenshot 2023-02-27 at 9.55.55 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/1/014103f080f2a929ff4e2dbb23ae273b2b9d5375.png)

Just remove the [in list \_\_\_ get #] block and use [j] instead.

If that doesn’t work for very long lists of locations, you may need to add a wait block at the end of the loop (try wait 0 seconds, then if that doesn’t work try wait 0.03 seconds).

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [February 28, 2023, 11:18pm UTC](https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159/4 "2023-02-28T23:18:40Z")

</div>

That works perfectly and is an amazing explanation. Thanks so much @tatiang !!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [May 29, 2023, 11:18pm UTC](https://community.thunkable.com/t/parsing-data-from-an-api-into-a-list-of-unknown-size/2300159/5 "2023-05-29T23:18:50Z")

</div>

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