This can be done without GSON or any other third party library:

@Throws(JSONException::class)
fun JSONObject.toMap(): Map<String, Any> {
    val map = mutableMapOf<String, Any>()
    val keysItr: Iterator<String> = this.keys()
    while (keysItr.hasNext()) {
        val key = keysItr.next()
        var value: Any = this.get(key)
        when (value) {
            is JSONArray -> value = value.toList()
            is JSONObject -> value = value.toMap()
        }
        map[key] = value
    }
    return map
}

@Throws(JSONException::class)
fun JSONArray.toList(): List<Any> {
    val list = mutableListOf<Any>()
    for (i in 0 until this.length()) {
        var value: Any = this[i]
        when (value) {
            is JSONArray -> value = value.toList()
            is JSONObject -> value = value.toMap()
        }
        list.add(value)
    }
    return list
}

Usage to convert JSONArray to List:

val jsonArray = JSONArray(jsonArrStr)
val list = jsonArray.toList()

Usage to convert JSONObject to Map:

val jsonObject = JSONObject(jsonObjStr)
val map = jsonObject.toMap()

More info is here

Answer from Michael Avoyan on Stack Overflow
🌐
GitHub
github.com › Kotlin › kotlinx.serialization › issues › 179
how to parse JSONArray to List<CustomObject> ? · Issue #179 · Kotlin/kotlinx.serialization
July 22, 2018 - I'm trying without success to serialize JSONArray to local variable List of CustomObjects, when CustomObject class is Serializable, i reread all the q&a, all the documents, I can not unders...
Author   xdma
🌐
Kotlin
kotlinlang.org › api › kotlinx.serialization › kotlinx-serialization-json › kotlinx.serialization.json › -json-array
JsonArray | kotlinx.serialization – Kotlin Programming Language
kotlinx-serialization-json/kotlinx.serialization.json/JsonArray · @Serializable(with = JsonArraySerializer::class · )class JsonArray(content: List<JsonElement>) : JsonElement, List<JsonElement> (source) Class representing JSON array, consisting of indexed values, where value is arbitrary JsonElement · Since this class also implements List interface, you can use traditional methods like List.get or List.getOrNull to obtain Json elements.
🌐
Codexpedia
codexpedia.com › home › kotlin › kotlin converting jsonarray to arraylist with extension functions
Kotlin converting JSONArray to ArrayList with extension functions - Codexpedia
March 24, 2022 - Convert string list from JSONArray to ArrayList fun JSONArray.toArrayList(): ArrayList { val list = arrayListOf() for (i in 0 until this.length()) { list.add(this.getString(i)) } return list } val messages = JSONArray("['aaa','bbb','ccc']") messages.toArrayList() Remove a string from JSONArray fun JSONArray.remove(value: String) { for (i in 0 until this.length()) { if (value == this.get(i)) { this.remove(i) return
🌐
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 · 中文 – 简体
🌐
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...
Find elsewhere
🌐
Kotlin Discussions
discuss.kotlinlang.org › android
How to make a KOTLIN list with JSON API bracket lists - Android - Kotlin Discussions
December 18, 2017 - Hello, I am trying to make a list in Kotlin from a JSon API. I did the tutorial from Udemy, and I made the Weather app. It works perfectly, but now I need to make a new list with an orders list. Here is the Weather API code : { “query”: { “results”: { “channel”: { “item” : { “forecast” : [ { “data”: 1 }, { “data”: 1 }, { “data”: 1 } ] } } } } } But now I need to make a list, and to take the previous example, it looks like this : { “query”: { “results”: { “channel”: { ...
🌐
TutorialsPoint
tutorialspoint.com › how-to-iterate-a-json-array-in-android-using-kotlin
How to iterate a JSON Array in Android using Kotlin?
This example demonstrates how to iterate a JSON Array in Android using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇉ New Project and fill all required details to create a new project.
🌐
CopyProgramming
copyprogramming.com › howto › kotlin-jsonarray-to-mutablelist-jsonobject-gt
Arrays: Converting JSONArray in Kotlin to a MutableList of JSONObject
May 31, 2023 - It appears that there is no built-in approach to transform JSONArray into List . Nevertheless, by utilizing Kotlin techniques, the Java code can be made significantly shorter. ... Take note that JSONArray values may differ from JSONObject (such as JSONArray ). To ensure that the array only ...
🌐
Baeldung
baeldung.com › home › kotlin › kotlin collections › parsing json arrays in kotlin with gson
Parsing JSON Arrays in Kotlin with Gson | Baeldung on Kotlin
March 19, 2024 - Let’s first create the Article ... List<Article>? = null ) { } Gson has the built-in feature of parsing to and from an array or a list automatically into JSON objects and vice versa....
🌐
GeeksforGeeks
geeksforgeeks.org › android-extract-data-from-json-array-using-retrofit-library-with-kotlin
Android – Extract Data From JSON Array using Retrofit Library with Kotlin | GeeksforGeeks
June 30, 2022 - JSON Object and JSON Array. JSON Array consists of individual JSON objects which are having same similar structure but have different values within it. JSON Array is used to parse the data in the form of a list or an array.