https://kotlinlang.org logo
Title
d

dave08

01/17/2023, 1:07 PM
If I have a
Map<String, JsonObject>
is there any way to easily modify one of the entry's value in the
JsonObject
?
I'd suppose there's no
MutableJsonObject
...? But maybe a more efficient plus operator implementation to merge two JsonObjects?
d

Desmond van der Meer

01/17/2023, 1:23 PM
JsonObject
implements
Map
and is just a wrapper around a
Map
. So you could do something like
val merged = JsonObject(previousJsonObject + mapOf("key" to JsonPrimitive("value")))
Or
previousJsonObject.toMutableMap()
, then modify that map and finally create a new
JsonObject
again that wraps the mutable map.
e

ephemient

01/17/2023, 1:26 PM
fyi there's a
Map.plus(Pair)
overload
d

dave08

01/17/2023, 1:27 PM
Thanks! That all sounds very good!
a

Adam S

01/17/2023, 2:16 PM