Skip to content

lisonge/kotlin-json5

Repository files navigation

kotlin-json5

kotlin multiplatform json5 for kotlinx.serialization

usage

implementation("li.songe:json5:0.0.1")

Json5String -> JsonElement

val element = Json5.parseToJson5Element("{a:1}")

JsonElement -> Json5String

val formatted: String = Json5.encodeToString(element, 2)

interop with kotlinx.serialization

val json = kotlinx.serialization.json.Json {
  // add your json config
  ignoreUnknownKeys = true
}

@kotlinx.serialization.Serializable
data class A(val id:Int)

// Json5String -> T
val a = json.decodeFromJson5String<A>("{id:0, b:''}")

// T -> Json5String
val formatted: String = json.encodeToJson5String(a)

Releases

No releases published

Languages