https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

bsimmons

05/15/2020, 2:47 PM
Hey all, I'm looking for a low-level JSON library like klaxon that works in a MPP. (Unfortunately I'm dealing with a nasty REST API and simple serialization isn't really flexible enough.) Any suggestions?
d

Dominaezzz

05/15/2020, 2:49 PM
Kotlinx.serialization?
b

bsimmons

05/15/2020, 2:52 PM
Yeah, I've been looking through the documentations, but there doesn't seems to be a way to manually create a JsonObject by hand.
c

Casey Brooks

05/15/2020, 2:54 PM
I saw this repo the other day which looked interesting and might be what you need, though I haven’t actually tried it https://github.com/kittinunf/Forge
g

gabin

05/15/2020, 2:55 PM
it can be created by json{} builder as well
☝️ 1
b

bsimmons

05/15/2020, 3:03 PM
@gabin Looks promising, I can't seem to find any documentation on that. Where can I find the builder?
g

gabin

05/15/2020, 3:05 PM
json { "additional key" to "value" }
b

bsimmons

05/15/2020, 3:15 PM
Hmmm, that's interesting. Just trying that out now. So it's basically converted a map to a JsonObject? I'm new to kotlin, which lines in the file you like do this?
(I'm just wondering, so that I can find clever features like this in the future.)
g

gabin

05/15/2020, 3:20 PM
it’s not basically a map. It makes json object from key-value pairs
val jsonBody = json { "user" to user, "email" to email }
You can see examples of json creation at the header of Json.kt file or search through kotlinx.serialization docs
b

bsimmons

05/15/2020, 3:35 PM
Ok, cool. Admittedly, I couldn't find any examples of this anywhere in the docs beyond that brief example in the source files.
Thanks for the help though!
2 Views