# \[Solved\] How do I loop through large JSON lists?

**URL:** https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065
**Category:** Questions about Thunkable X
**Tags:** solved, beginner
**Created:** [March 31, 2022, 9:07am UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065 "2022-03-31T09:07:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![shihminh](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@shihminh](https://community.thunkable.com/u/shihminh)
#### Post date: [March 31, 2022, 9:07am UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/1 "2022-03-31T09:07:26Z")

</div>

It’s really strange and bugs me.  
The program works just fine when the index of loop is 5 or 10 .  
But it was just crushed when I set the index to the length of an object.  
I need to clear the cookies so that I can continue to run the program.  
Any advice?

[Here is the demo.](https://youtu.be/M1xiKwJ5qpc)

My code

 ![bug](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/e/4e348d5bfda0e631bee79f83ccbce47f818d7e98.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: [March 31, 2022, 11:09am UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/2 "2022-03-31T11:09:16Z")

</div>

Is the top level of the JSON response an array/list? Because if it isn’t, this won’t work.

Post the text of your JSON response.

---

<div class="post-metadata">

### Author: ![shihminh](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@shihminh](https://community.thunkable.com/u/shihminh)
#### Post date: [March 31, 2022, 11:19am UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/4 "2022-03-31T11:19:10Z")

</div>

Hi  
The JSON response is from the [request url](https://ptx.transportdata.tw/MOTC/v2/Bus/EstimatedTimeOfArrival/City/NewTaipei/PassThrough/Station/2559?%24format=JSON).

```auto
[{"StopUID":"NWT138796","StopID":"138796","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16588","RouteID":"16588","RouteName":{"Zh_tw":"264","En":"264"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT123513","StopID":"123513","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16423","RouteID":"16423","RouteName":{"Zh_tw":"930","En":"930"},"Direction":1,"EstimateTime":766,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT178949","StopID":"178949","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17523","RouteID":"17523","RouteName":{"Zh_tw":"806","En":"806"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT178643","StopID":"178643","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17517","RouteID":"17517","RouteName":{"Zh_tw":"99","En":"99"},"Direction":1,"EstimateTime":631,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT140070","StopID":"140070","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16603","RouteID":"16603","RouteName":{"Zh_tw":"920","En":"920"},"Direction":1,"EstimateTime":88,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT149611","StopID":"149611","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16689","RouteID":"16689","RouteName":{"Zh_tw":"793","En":"793"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT140846","StopID":"140846","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16614","RouteID":"16614","RouteName":{"Zh_tw":"930延","En":"930Extend"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT149286","StopID":"149286","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16685","RouteID":"16685","RouteName":{"Zh_tw":"657延","En":"657sub"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT199118","StopID":"199118","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17668","RouteID":"17668","RouteName":{"Zh_tw":"982","En":"982"},"Direction":1,"EstimateTime":1898,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT199116","StopID":"199116","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17679","RouteID":"17679","RouteName":{"Zh_tw":"982區","En":"982Shuttle"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT34188","StopID":"34188","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10151","RouteID":"10151","RouteName":{"Zh_tw":"701","En":"701"},"Direction":0,"EstimateTime":1097,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT208906","StopID":"208906","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT18729","RouteID":"18729","RouteName":{"Zh_tw":"920副","En":"920Sub"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT15107","StopID":"15107","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10162","RouteID":"10162","RouteName":{"Zh_tw":"245","En":"245"},"Direction":0,"EstimateTime":752,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT15842","StopID":"15842","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10163","RouteID":"10163","RouteName":{"Zh_tw":"656","En":"656"},"Direction":0,"EstimateTime":355,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT15980","StopID":"15980","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10164","RouteID":"10164","RouteName":{"Zh_tw":"657","En":"657"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT179283","StopID":"179283","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17527","RouteID":"17527","RouteName":{"Zh_tw":"813區","En":"813Shuttle"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT179236","StopID":"179236","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17526","RouteID":"17526","RouteName":{"Zh_tw":"813","En":"813"},"Direction":1,"EstimateTime":1149,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT127415","StopID":"127415","StopName":{"Zh_tw":"中山國中","En":"JhongShan Junior High School"},"RouteUID":"NWT16462","RouteID":"16462","RouteName":{"Zh_tw":"910","En":"910"},"Direction":1,"EstimateTime":984,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT127445","StopID":"127445","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16463","RouteID":"16463","RouteName":{"Zh_tw":"藍35","En":"BL35"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT127876","StopID":"127876","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16471","RouteID":"16471","RouteName":{"Zh_tw":"藍33","En":"BL33"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT205981","StopID":"205981","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT18318","RouteID":"18318","RouteName":{"Zh_tw":"918區","En":"918Shuttle"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"}]

```

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [March 31, 2022, 11:48am UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/5 "2022-03-31T11:48:56Z")

</div>

I just made a quick test and it worked fine.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/b/1b42d04f77bc30efa3dbf7245a65b990c0ccfbad.png)

Output  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/7/2782c7cf383f4d39b0e9820c88b55a6d53fbc40c.png)

**[Note]**  
I noticed that first entry does not have `EstimateTime` field and this could cause errors when parsing.

---

<div class="post-metadata">

### Author: ![shihminh](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@shihminh](https://community.thunkable.com/u/shihminh)
#### Post date: [March 31, 2022, 12:48pm UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/6 "2022-03-31T12:48:16Z")

</div>

Thank you so much.  
Bug fixed after I notice your [Note] 😀 😀 😀  
Here is modified code.

 ![bugfixed](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/9/79859ba0506c137d2f997a34dcfe10224ec4a8d5.png)

The original code doesn’t work when the EstimateTime is null.

 ![responsejson](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/9/79a90abcc174154fa89cf3157982bfda2392ee9e.png)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [March 31, 2022, 12:54pm UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/7 "2022-03-31T12:54:16Z")

</div>

I would do it this way

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/0/1018e1b351c77364774795de3fe0acc78887cd5f.png)

The output would be like this  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/a/cac8b40a9356a21f96316b090f1f188918028c1a.png)

---

<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: [June 29, 2022, 12:54pm UTC](https://community.thunkable.com/t/solved-how-do-i-loop-through-large-json-lists/1811065/8 "2022-06-29T12:54:28Z")

</div>

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