Unfortunately, JsonArray does not expose an iterator. So you will have to iterate through it using an index range:

for (i in 0 until persons.length()) {
    val item = persons.getJSONObject(i)

    // Your code here
}
Answer from 0x60 on Stack Overflow
🌐
Kotlin Discussions
discuss.kotlinlang.org › javascript
Iterating over Json properties - JavaScript
August 29, 2016 - Hi there! I’m unsuccessfully trying to find a way to iterate over a Json object (which is expected to only contain properties with String values) so that I can fill a Map<String,String> from it. In either way I end up w…
🌐
Baeldung
baeldung.com › home › kotlin › kotlin collections › iterate through a jsonarray in kotlin
Iterate Through a JSONArray in Kotlin | Baeldung on Kotlin
September 7, 2024 - for (book in booksJSONArray) { println("${(book as JSONObject).get("book_name")} by ${(book as JSONObject).get("author")}") }
🌐
TutorialsPoint
tutorialspoint.com › how-to-iterate-a-json-array-in-android-using-kotlin
How to iterate a JSON Array in Android using Kotlin?
import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import org.json.JSONObject @Suppress("NAME_SHADOWING") class MainActivity : AppCompatActivity() { private lateinit var textView: TextView var strJson = ("{ \"Employee\" :[{\"ID\":\"01\",\"Name\":\"Sam\",\"Salary\":\"50000\"}," + "{\"ID\":\"02\",\"Name\":\"Shankar\",\"Salary\":\"60000\"}] }") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" textView = findViewById(R.id.textView) val data = String
🌐
Webkul
webkul.com › home › how to iterate through jsonobject in java and kotlin
How to Iterate through JSONObject in Java and Kotlin - Webkul Blog
January 16, 2026 - String jsonString = "{\"name\":\"John\", \"age\":30, \"hobbies\":[\"reading\", \"gaming\", \"coding\"]}"; JSONObject mainObject = new JSONObject(jsonString); Iterator<String> mainKeys = mainObject.keys(); while (mainKeys.hasNext()) { String key = mainKeys.next(); Object value = mainObject.get(key); if (value instanceof JSONArray) { JSONArray jsonArray = (JSONArray) value; for (int i = 0; i < jsonArray.length(); i++) { Log.d("JSON", "Array Item: " + jsonArray.get(i)); } } } Kotlin’s smart casting and concise syntax simplify nested JSONArray handling.
🌐
GitHub
github.com › android › android-ktx › issues › 241
JSONObject & JSONArray extensions · Issue #241 · android/android-ktx
February 7, 2018 - T) } } inline fun <reified T> JSONArray.forEachNotNull(action: (T) -> Unit) { (0..length()).forEach { action(get(it) as T) } } // Summary inline fun <reified T: Comparable<T>> JSONArray.max() = toList<T>().filterNotNull().max() inline fun <reified T: Comparable<T>> JSONArray.min() = toList<T>().filterNotNull().min() ...
Author   ethanblake4
🌐
Android Developers
developer.android.com › api reference › jsonarray
JSONArray | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Find elsewhere
🌐
Android Developers
developer.android.com › api reference › jsonobject
JSONObject | API reference | Android Developers
February 26, 2026 - Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.collections › for-each.html
forEach
Kotlin is a concise and multiplatform programming language by JetBrains. Enjoy coding and build server-side, mobile, web, and desktop applications efficiently.
🌐
Edureka Community
edureka.co › home › community › categories › java › iterate over a jsonobject
Iterate over a JSONObject | Edureka Community
June 27, 2018 - JSON library called JSONObject is used(I don't mind switching if I need to) We know how to iterate over ... http://url3.com//", "shares": 15 } }
🌐
GeeksforGeeks
geeksforgeeks.org › android-extract-data-from-json-array-using-volley-library-with-kotlin
Android - Extract Data From JSON Array using Volley Library with Kotlin - GeeksforGeeks
July 22, 2022 - 5 min read JSON Parsing in Android Using Volley Library with Kotlin · JSON is a JavaScript object notation which is a format to exchange the data from the server. JSON stores the data in a lightweight format. With the help of JSON, we can access the data in the form of JsonArray, JsonObject, and JsonStringer.
🌐
Kotlin Discussions
discuss.kotlinlang.org › javascript
Arraylist from json can not be iterated - JavaScript
August 12, 2017 - i created a ArrayList with PersonDto objects and transform it to a json string on the server to send it to the client. in the client i try to parse this string back to the ArrayList of PersonDto objects but only get an Array back val listPerson = JSON.parse (data...
🌐
Kotlin
kotlinlang.org › api › kotlinx.serialization › kotlinx-serialization-json › kotlinx.serialization.json › -json-object
JsonObject | kotlinx.serialization – Kotlin Programming Language
Class representing JSON object, consisting of name-value pairs, where value is arbitrary JsonElement · Since this class also implements Map interface, you can use traditional methods like Map.get or Map.getValue to obtain Json elements
🌐
BezKoder
bezkoder.com › home › kotlin – convert json to object and vice versa using jackson
Kotlin – Convert JSON to Object and vice versa using Jackson - BezKoder
December 13, 2020 - import com.fasterxml.jackson.module.kotlin.* val jsonList = """[{"name": "bezkoder", "age": "26", "messages" : ["hello","becoming zKoder"]}, {"name":"bezkoder Master","age":30,"messages":["I am Kotlin Master","still learning Kotlin"]}]""" val mapper = jacksonObjectMapper() var personList: List · = mapper.readValue(jsonList) personList.forEach { println(it) } The result will look like this.