jsonkotlinklaxon

Klaxon's JSON pretty printing outputs "["result"]"


val time = json.lookup<String?>("query.results.channel.title").toJsonString(true)

outputs

["Yahoo! Weather - Nome,AK,US"]

is there a way to get the output without the brackets and the quotation marks ?

I guess that

.replace("[\"","").replace("\"]","")

isn't the best way


Solution

  • The brackets are contained in the default implementation (see https://github.com/cbeust/klaxon/blob/master/src/main/kotlin/com/beust/klaxon/DSL.kt at the very bottom function appendJsonStringImpl)

    So it is not possible, to remove them by configuration.

    It might work if you write an extension function for this particular class, but i guess this is not what you want.

    So this is currently not possible without writing your own extension(-function).