Package-level declarations

JSON serialization format implementation, JSON tree data structures with builders for them, and JSON-specific serializers.

JSON serialization format implementation, JSON tree data structures with builders for them, and JSON-specific serializers.

JSON serialization format implementation, JSON tree data structures with builders for them, and JSON-specific serializers.

Types

Link copied to clipboard

Defines which classes and objects should have their serial name included in the json as so-called class discriminator.

Link copied to clipboard

Description of JSON input shape used for decoding to sequence.

Link copied to clipboard
sealed class Json : StringFormat

The main entry point to work with JSON serialization. It is typically used by constructing an application-specific instance, with configured JSON-specific behaviour and, if necessary, registered in SerializersModule custom serializers. Json instance can be configured in its Json {} factory function using JsonBuilder. For demonstration purposes or trivial usages, Json companion can be used instead.

Link copied to clipboard

Class representing JSON array, consisting of indexed values, where value is arbitrary JsonElement

Link copied to clipboard

DSL builder for a JsonArray. To create an instance of builder, use buildJsonArray build function.

Link copied to clipboard

Builder of the Json instance provided by Json { ... } factory function.

Link copied to clipboard

Specifies key for class discriminator value used during polymorphic serialization in Json. Provided key is used only for an annotated class and its subclasses; to configure global class discriminator, use JsonBuilder.classDiscriminator property.

Link copied to clipboard

Configuration of the current Json instance available through Json.configuration and configured with JsonBuilder constructor.

Link copied to clipboard
abstract class JsonContentPolymorphicSerializer<T : Any>(baseClass: KClass<T>) : KSerializer<T>

Base class for custom serializers that allows selecting polymorphic serializer without a dedicated class discriminator, on a content basis.

Link copied to clipboard

Decoder used by Json during deserialization. This interface can be used to inject desired behaviour into a serialization process of Json.

Link copied to clipboard

Class representing single JSON element. Can be JsonPrimitive, JsonArray or JsonObject.

Link copied to clipboard

Encoder used by Json during serialization. This interface can be used to inject desired behaviour into a serialization process of Json.

Link copied to clipboard

Indicates that the field can be represented in JSON with multiple possible alternative names. Json format recognizes this annotation and is able to decode the data using any of the alternative names.

Link copied to clipboard

Represents naming strategy — a transformer for serial names in a Json format. Transformed serial names are used for both serialization and deserialization. A naming strategy is always applied globally in the Json configuration builder (see JsonBuilder.namingStrategy).

Link copied to clipboard

Class representing JSON null value

Link copied to clipboard

Class representing JSON object, consisting of name-value pairs, where value is arbitrary JsonElement

Link copied to clipboard

DSL builder for a JsonObject. To create an instance of builder, use buildJsonObject build function.

Link copied to clipboard

Class representing JSON primitive value. JSON primitives include numbers, strings, booleans and special null value JsonNull.

Link copied to clipboard
abstract class JsonTransformingSerializer<T : Any>(tSerializer: KSerializer<T>) : KSerializer<T>

Base class for custom serializers that allows manipulating an abstract JSON representation of the class before serialization or deserialization.

Properties

Link copied to clipboard

Returns content of current element as boolean

Link copied to clipboard

Returns content of current element as boolean or null if current element is not a valid representation of boolean

Link copied to clipboard

Content of the given element without quotes or null if current element is JsonNull

Link copied to clipboard

Returns content of current element as double

Link copied to clipboard

Returns content of current element as double or null if current element is not a valid representation of number

Link copied to clipboard

Returns content of current element as float

Link copied to clipboard

Returns content of current element as float or null if current element is not a valid representation of number

Link copied to clipboard

Returns content of the current element as int

Link copied to clipboard

Returns content of the current element as int or null if current element is not a valid representation of number

Link copied to clipboard

Convenience method to get current element as JsonArray

Link copied to clipboard

Convenience method to get current element as JsonNull

Link copied to clipboard

Convenience method to get current element as JsonObject

Link copied to clipboard

Convenience method to get current element as JsonPrimitive

Link copied to clipboard

Returns content of current element as long

Link copied to clipboard

Returns content of current element as long or null if current element is not a valid representation of number

Functions

Link copied to clipboard

Adds the given boolean value to a resulting JSON array.

Adds null to a resulting JSON array.

Adds the given numeric value to a resulting JSON array.

Adds the given string value to a resulting JSON array.

Link copied to clipboard

Adds the given boolean values to a resulting JSON array.

Adds the given numeric values to a resulting JSON array.

Adds the given string values to a resulting JSON array.

Link copied to clipboard

Adds the JSON array produced by the builderAction function to a resulting JSON array.

Link copied to clipboard

Adds the JSON object produced by the builderAction function to a resulting JSON array.

Link copied to clipboard
inline fun buildJsonArray(builderAction: JsonArrayBuilder.() -> Unit): JsonArray

Builds JsonArray with the given builderAction builder. Example of usage:

Link copied to clipboard
inline fun buildJsonObject(builderAction: JsonObjectBuilder.() -> Unit): JsonObject

Builds JsonObject with the given builderAction builder. Example of usage:

Link copied to clipboard
inline fun <T> Json.decodeFromDynamic(dynamic: dynamic): T

A reified version of decodeFromDynamic.

Converts native JavaScript objects into Kotlin ones, verifying their types.

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> 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
inline fun <T> Json.encodeToDynamic(value: T): dynamic

A reified version of encodeToDynamic.

Converts Kotlin data structures to plain Javascript objects

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
fun Json(from: Json = Json.Default, builderAction: JsonBuilder.() -> Unit): Json

Creates an instance of Json configured from the optionally given Json instance and adjusted with builderAction.

Link copied to clipboard

Creates a JsonPrimitive from the given boolean.

Creates JsonNull.

Creates a JsonPrimitive from the given number.

Creates a JsonPrimitive from the given string.

Creates a numeric JsonPrimitive from the given UByte.

Creates a numeric JsonPrimitive from the given UInt.

Creates a numeric JsonPrimitive from the given ULong.

Creates a numeric JsonPrimitive from the given UShort.

Link copied to clipboard

Creates a JsonPrimitive from the given string, without surrounding it in quotes.

Link copied to clipboard

Add the given boolean value to a resulting JSON object using the given key.

Add null to a resulting JSON object using the given key.

Add the given numeric value to a resulting JSON object using the given key.

Add the given string value to a resulting JSON object using the given key.

Link copied to clipboard

Add the JSON array produced by the builderAction function to a resulting JSON object using the given key.

Link copied to clipboard

Add the JSON object produced by the builderAction function to a resulting JSON object using the given key.