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

Stylianos Gakis

02/08/2022, 4:28 PM
Is there a KMP option to deal with raw Json objects? Like JSONObject from android? I am aware of kotlinx.serialization but I am interested in constructing arbitrary untyped Json objects and adding arrays/values inside it instead of mapping from/to Kotlin classes
j

jw

02/08/2022, 4:29 PM
kotlinx.serialization offers that
s

Stylianos Gakis

02/08/2022, 4:29 PM
Alright, my bad, I’ll have to look further into that, thanks a lot!
s

Stylianos Gakis

02/08/2022, 4:30 PM
Wow that is just… amazing how could I have missed it? Thank you very much, I really appreciate the speedy response Jake!
After working with it a bit, it’s amazing for constructing Json objects from scratch, but isn’t as convenient in a use case I have of also having an existing Json object and having to edit some specific fields inside it. There isn’t as far as I can tell a
buildJsonObject
alternative that takes an existing
JsonObject
as initial state, and working on a
JsonObject
directly trying to edit it doesn’t seem to be what I want either as it’s immutable by default and there isn’t a Mutable alternative to it 🤔 Am I missing something again in the API or is it just a matter of making my own implementation of it by turning it into a
.toMutableMap()
, doing the edits I want, and then turning it back into a
JsonObject
myself.