
Parses JWT payloads into JSON objects, offering a simple integration method and a safe retrieval function for extracting JSON values with optional default values.
A lightweight Kotlin Multiplatform (KMP) library for parsing the payload section of a JWT token on both Android and iOS.
It provides a simple API to decode JWT payloads into a Kotlin object using kotlinx.serialization.
kotlinx.serialization
The library is published on Maven Central.
[versions]
simpleJwtParser = "2.0.0"
[libraries]
simpleJwtParser = { module = "io.github.jmseb3:simpleJwtParser", version.ref = "simpleJwtParser" }Then add the dependency:
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.simpleJwtParser)
}
}
}
}kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.github.jmseb3:simpleJwtParser:2.0.0")
}
}
}
}Use JwtParser.parseToJsonObject() to parse the payload section of a JWT token into a Payload object.
val payload: Payload = JwtParser.parseToJsonObject(jwtToken)The Payload class supports the default JWT claims:
iss — Issuersub — Subjectaud — Audienceexp — Expiration Timenbf — Not Beforeiat — Issued Atjti — JWT IDYou can also access custom claims using the get() function.
val loginType = payload.get(
key = "member_login_type",
defaultValue = ""
)The library provides safe extension methods for JsonObject.
val typeOfLogin: String? =
jsonObject
.safeGet("member_login_type")
?.jsonPrimitive
?.contentval typeOfLogin: String =
jsonObject
.safeGet(
key = "member_login_type",
defaultValue = ""
)
.jsonPrimitive
.contentkotlinx.serializationLicensed under the Apache License 2.0.
See the LICENSE file for details.
A lightweight Kotlin Multiplatform (KMP) library for parsing the payload section of a JWT token on both Android and iOS.
It provides a simple API to decode JWT payloads into a Kotlin object using kotlinx.serialization.
kotlinx.serialization
The library is published on Maven Central.
[versions]
simpleJwtParser = "2.0.0"
[libraries]
simpleJwtParser = { module = "io.github.jmseb3:simpleJwtParser", version.ref = "simpleJwtParser" }Then add the dependency:
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.simpleJwtParser)
}
}
}
}kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.github.jmseb3:simpleJwtParser:2.0.0")
}
}
}
}Use JwtParser.parseToJsonObject() to parse the payload section of a JWT token into a Payload object.
val payload: Payload = JwtParser.parseToJsonObject(jwtToken)The Payload class supports the default JWT claims:
iss — Issuersub — Subjectaud — Audienceexp — Expiration Timenbf — Not Beforeiat — Issued Atjti — JWT IDYou can also access custom claims using the get() function.
val loginType = payload.get(
key = "member_login_type",
defaultValue = ""
)The library provides safe extension methods for JsonObject.
val typeOfLogin: String? =
jsonObject
.safeGet("member_login_type")
?.jsonPrimitive
?.contentval typeOfLogin: String =
jsonObject
.safeGet(
key = "member_login_type",
defaultValue = ""
)
.jsonPrimitive
.contentkotlinx.serializationLicensed under the Apache License 2.0.
See the LICENSE file for details.