for Object from json in kotlin code example

Example 1: kotlin json

import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@Serializable
class MyJsonClass(val name: String, val optionalInt: Int = 5)

fun main() {
  val jsonToEncode = MyJsonClass( "Alice", 10 )
  val encodedJson  = Json.encodeToString( jsonToEncode )
  val decodedJson  = Json.decodeFromString<MyJsonClass>( jsonString )
}

Example 2: kotlin jsonobject from string

val data = JSONObject("""{"name":"test name", "age":25}""")