kotlinx-serialization / kotlinx.serialization.json / JsonElement

JsonElement

(common, js, jvm, native) sealed class JsonElement

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

JsonElement.toString properly prints JSON tree as valid JSON, taking into account quoted values and primitives. Whole hierarchy is serializable, but only when used with Json as JsonElement is purely JSON-specific structure which has a meaningful schemaless semantics only for JSON.

The whole hierarchy is serializable only by Json format.

Properties

(common, js, jvm, native)

isNull

Checks whether current element is JsonNull

val isNull: Boolean
(common, js, jvm, native)

jsonArray

Convenience method to get current element as JsonArray

open val jsonArray: JsonArray
(common, js, jvm, native)

jsonNull

Convenience method to get current element as JsonNull

open val jsonNull: JsonNull
(common, js, jvm, native)

jsonObject

Convenience method to get current element as JsonObject

open val jsonObject: JsonObject
(common, js, jvm, native)

primitive

Convenience method to get current element as JsonPrimitive

open val primitive: JsonPrimitive

Functions

(common, js, jvm, native)

contains

Checks whether element represents a JsonObject and contains given key. Returns false if element is not a JsonObject.

operator fun contains(key: String): Boolean

Inheritors

(common, js, jvm, native)

JsonArray

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

data class JsonArray : JsonElement, List<JsonElement>
(common, js, jvm, native)

JsonObject

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

data class JsonObject : JsonElement, Map<String, JsonElement>
(common, js, jvm, native)

JsonPrimitive

Class representing JSON primitive value. Can be either JsonLiteral or JsonNull.

sealed class JsonPrimitive : JsonElement