Is there a lightweight(not kotlinx.serializaion) l...
# multiplatform
h
Is there a lightweight(not kotlinx.serializaion) library to simply parse json string one way into Maps/Lists for multiplatform?
t
Create your own with expect/actual, it takes about 30-50 lines per platform for iOS/Android
h
I need it for JS also. Guess it's time to write my own json parser.
s
you can start from here: https://github.com/Kotlin/kotlinx.serialization/tree/master/json it is json parser in separate module; however, binary artifacts for it on JVM/JS are not published (they’re part of a bigger kotlinx.serialization). Probably you want to cut-and-paste it or make your fork with publishing.
đź‘Ť 1
h
Thanks, will look into it.
What's the purpose of
CharArray.createString(length: Int): String
? Why not just do
String(buf)
?
s
There was no such constructor at that time: https://youtrack.jetbrains.com/issue/KT-23356
j
If you're willing to do a little work, you could always make something based off this - https://github.com/cbeust/klaxon/blob/master/src/main/kotlin/com/beust/klaxon/JsonReader.kt You'll have to replace the parts the represent the JVM with others though.
Also, I've already done some of that work if you want to pull from mine. Pull in RawJsonReader and RawJsonWriter from here: https://github.com/UnknownJoe796/kotlinx/tree/master/kotlinx-common/src/main/kotlin/com/lightningkite/kotlinx/serialization/json
t
Looks like there is some need in expect/actual json parser for 3 platforms
s
Not sure why
kotlinx.serialization
is not “lightweight”. Btw, I think even if you include it without plugin, you’ll be able to do parsing to maps.
t
The main problem for me at the moment is binary incompatibility for KN updates so I have own source-based library
s
what do you mean? it’s updated to 0.8.1 and probably shouldn’t face issues even with recent dev build
h
I already pulled out classes from
kotlinx.serializatoin
, and wrapped it in a library Exactly what I needed.