This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun flattenJson(json: Map<String, Any>, parentKey: String = ""): Map<String, Any> { | |
val result = mutableMapOf<String, Any>() | |
for ((key, value) in json) { | |
val fullKey = if (parentKey.isEmpty()) key else "$parentKey.$key" | |
when (value) { | |
is Map<*, *> -> { | |
// If the value is another JSON object, recursively flatten it | |
val nestedMap = value as Map<String, Any> |