Klaxon (JSON) convert whole object including object name

88 Views Asked by At

I'm using Klaxon to convert object to JSON objects but it creates an object like so:

data class Welcome(
    val text: String
)

results in:

{
    text: "some value"
}

But i want something like

"Welcome"{
    text: "Some value"
}
1

There are 1 best solutions below

0
On BEST ANSWER

As a solution i switched to using org.json and used the following code to get the result I wanted:

val jsonString = """
    {
        "blog": {
            "title": "$title",
             "content": "$content"
        }
    }
"""
var jsonBlogObject = JSONObject(jsonString)
jsonBlogObject.put("someting", "some value")