Default

object Default : Json(source)

The default instance of Json with default configuration.

Example of usage:

@Serializable
class Project(val name: String, val language: String)

val data = Project("kotlinx.serialization", "Kotlin")
// Prints {"name":"kotlinx.serialization","language":"Kotlin"}
println(Json.encodeToString(data))

Properties

Link copied to clipboard
Link copied to clipboard
open val serializersModule: <Error class: unknown class>

Functions

Link copied to clipboard
fun <T> decodeFromJsonElement(deserializer: <Error class: unknown class><T>, element: JsonElement): T

Deserializes the given element into a value of type T using the given deserializer.

Link copied to clipboard

Deserializes the given json element into a value of type T using a deserializer retrieved from reified type parameter.

Link copied to clipboard

Deserializes the contents of given stream to the value of type T using UTF-8 encoding and deserializer retrieved from the reified type parameter.

Deserializes JSON from stream using UTF-8 encoding to a value of type T using deserializer.

Link copied to clipboard
inline fun <T> decodeFromString(string: String): T

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

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

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

Link copied to clipboard
inline fun <T> Json.decodeToSequence(stream: InputStream, format: DecodeSequenceMode = DecodeSequenceMode.AUTO_DETECT): Sequence<T>

Transforms the given stream into lazily deserialized sequence of elements of type T using UTF-8 encoding and deserializer retrieved from the reified type parameter. Unlike decodeFromStream, stream is allowed to have more than one element, separated as format declares.

fun <T> Json.decodeToSequence(stream: InputStream, deserializer: DeserializationStrategy<T>, format: DecodeSequenceMode = DecodeSequenceMode.AUTO_DETECT): Sequence<T>

Transforms the given stream into lazily deserialized sequence of elements of type T using UTF-8 encoding and deserializer. Unlike decodeFromStream, stream is allowed to have more than one element, separated as format declares.

Link copied to clipboard
fun <T> encodeToJsonElement(serializer: <Error class: unknown class><T>, value: T): JsonElement

Serializes the given value into an equivalent JsonElement using the given serializer

Link copied to clipboard
inline fun <T> Json.encodeToJsonElement(value: T): JsonElement

Serializes the given value into an equivalent JsonElement using a serializer retrieved from reified type parameter.

Link copied to clipboard

Serializes given value to stream using UTF-8 encoding and serializer retrieved from the reified type parameter.

Serializes the value with serializer into a stream using JSON format and UTF-8 encoding.

Link copied to clipboard
inline fun <T> encodeToString(value: T): String

Serializes the value of type T into an equivalent JSON using serializer retrieved from the reified type parameter.

fun <T> encodeToString(serializer: <Error class: unknown class><T>, value: T): String

Serializes the value into an equivalent JSON using the given serializer. This method is recommended to be used with an explicit serializer (e.g. the custom or third-party one), otherwise the encodeToString(value: T) version might be preferred as the most concise one.

Link copied to clipboard

Deserializes the given JSON string into a corresponding JsonElement representation.