package co.ab180.airbridge.reactnative.extension import org.json.JSONArray import org.json.JSONObject import java.util.LinkedList internal fun JSONObject.toMap(): Map { val map = HashMap() for (key in keys()) { opt(key)?.also { when (it) { is JSONObject -> { map[key] = it.toMap() } is JSONArray -> { map[key] = it.toList() } else -> { map[key] = it } } } } return map } internal fun JSONArray.toList(): List { val list = LinkedList() for (index in 0 until length()) { opt(index)?.also { when (it) { is JSONObject -> { list.add(it.toMap()) } is JSONArray -> { list.add(it.toList()) } else -> { list.add(it) } } } } return list }