I need to parse any dynamic JSON (In the Kotlin Multiplatform project) to key-value pair and convert it to a nested list after. I started with the default .toMap()
function, but it can't go deeper to parse ArrayList<*> Any idea how to do it?
Sample JSON:
{
"id": "0001",
"type": "donut",
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5004", "type": "Maple" }
]
}
Thanks in advance!
Your
@Serializable data class
should look like this:Kotlinx.serialization should parse your json without any problems into
MainClass.serializable()
.