decodeFromString

fun <T> decodeFromString(deserializer: <Error class: unknown class><T>, string: String): T(source)

Deserializes the given JSON string into a value of type T using the given deserializer. Example:

@Serializable
data class Project(val name: String, val language: String)
// Project(name=kotlinx.serialization, language=Kotlin)
println(Json.decodeFromString(Project.serializer(), """{"name":"kotlinx.serialization","language":"Kotlin"}"""))

Throws

SerializationException

if the given JSON string is not a valid JSON input for the type T

IllegalArgumentException

if the decoded input cannot be represented as a valid instance of type T


inline fun <T> decodeFromString(string: String): T(source)

Decodes and deserializes the given JSON string to the value of type T using deserializer retrieved from the reified type parameter. Example:

@Serializable
data class Project(val name: String, val language: String)
// Project(name=kotlinx.serialization, language=Kotlin)
println(Json.decodeFromString<Project>("""{"name":"kotlinx.serialization","language":"Kotlin"}"""))

Throws

SerializationException

in case of any decoding-specific error

IllegalArgumentException

if the decoded input is not a valid instance of T