I have used Klaxon for JSON parsing for a bit but ...
# announcements
a
I have used Klaxon for JSON parsing for a bit but I can’t find if there is a function to merge JSON documents. Anyone know if there is one? If there isn’t anyone know of a good lib for this?
guess I can just use
Copy code
fun merge(initial: JsonObject, toMerge: JsonObject, overwrite: Boolean = true): JsonObject {

    val result = initial.copy()
    for ((k, v) in toMerge) {
        val current = result[k]
        if (current == null) {
            result[k] = v
        } else {
            if (current is JsonObject) {
                assert(v is JsonObject)
                result[k] = merge(current, v as JsonObject, overwrite) // TODO: is this bad code
            } else if (overwrite) {
                result[k] = v
            }
        }
    }
    return result
}
e
the author is here on slack, you may want to ask him directly