json5k
json5k copied to clipboard
how to convert json5String to JsonElement
Thank you for your open source work
But I encountered some problems
val name = "kotlinx.serialization.json.JsonElementSerializer"
val JsonElementSerializer = Class.forName(name).kotlin.objectInstance as KSerializer<JsonElement>
Json5.decodeFromString(JsonElementSerializer, "{a:1}")
but I get error
java.lang.IllegalStateException: This serializer can be used only with Json format.Expected Decoder to be JsonDecoder, got class io.github.xn32.json5k.deserialization.MainDecoder
The JSON element serializer only supports the KxS JSON encoder/decoder. It doesn't support json5
Also either use the inline versions of the functions or use JsonElement.serializer(), don't use reflection here
I need to convert a JSON5 string to a JSON string, and then convert this JSON string to a JsonElement.
So is it possible to use this library to directly convert a JSON5 string to a JsonElement?
https://github.com/lisonge/kotlin-json5