I'm parsing a file with list of JSON objects in Ko...
# javascript
j
I'm parsing a file with list of JSON objects in Kotlin/JS, and some of them (for some stupid reason I don't have control over), have some of the data fields in recursively-quoted JSON. I'm running into a problem I don't understand, code in thread.
I"m doing
Copy code
val data = rawData.split("\r\n", "\n")
    .filter { it.isNotEmpty() }
    .map { JSON.parse<dynamic>(it) }
    .map {
        if (it.data is String) {
            val lineData = JSON.parse<dynamic>(it.data)
            lineData.forEach { entry ->
                it[entry.key] = entry.value
            }
        }
        it
    }
    .toList()
But this gives me
Copy code
e: /Users/jlennox/Git/jvb-dashboard/src/main/kotlin/DumpViewer.kt: (34, 45): Expected a value of type dynamic. Assignment operation is not an expression, so it does not return any value
on the
forEach
. What am I doing wrong?
Alternatively, is there a way to call JS
Object.assign
in Kotlin/JS?
Ok,
js("Object").assign(it, lineData)
worked, but I still don't understand what's wrong with the
forEach
t
lineData
-
Array
?
j
It should be a JS object
t
JS object has no
forEach
method
j
It was failing at compile time though, which was the weird thing?
e
Still working on it, or solved? If you haven't, would be nice to have data sample