Daniel Pitts
12/17/2024, 5:39 PMimport com.stochastictinkr.json.*
fun main() {
val obj = jsonObject {
"name"("John Doe")
"age"(25)
"address" {
"number"(123)
"street"("Main Street")
"city"("Anytown")
"state"("AS")
"zip"(12345)
}
"phoneNumbers"[{
add("555-1234")
add("555-5678")
}]
"favoriteColor"(null)
"averageScore"(85.5)
}
println(JsonWriter.Pretty.writeToString(obj))
}
Resulting JSON:
{
"name": "John Doe",
"age": 25,
"address": {
"number": 123,
"street": "Main Street",
"city": "Anytown",
"state": "AS",
"zip": 12345
},
"phoneNumbers": [
"555-1234",
"555-5678"
],
"favoriteColor": null,
"averageScore": 85.5
}
Daniel Pitts
12/17/2024, 5:41 PMCLOVIS
12/17/2024, 8:22 PMCLOVIS
12/17/2024, 8:23 PMString.invoke()
because it's very easy to do weird things with, but that seems like a good case 🤔
I probably would've went with
jsonObject {
"name" set "John Doe"
"age" set 25
// …
}
but that's personal preference I thinkCLOVIS
12/17/2024, 8:24 PMKlitos Kyriacou
12/18/2024, 10:20 AMdave08
12/18/2024, 10:44 AMadd(...)
could be +"..."
maybe (like in kotlinx html)CLOVIS
12/18/2024, 10:48 AMdave08
12/18/2024, 10:51 AM"..."(...)
vs "..." set ...
and +"..."
vs add(...)
... 😁. Not that I have any particular preference here... just seems more consistent.Daniel Pitts
12/18/2024, 2:10 PM:
operator for the object keys.dave08
12/18/2024, 2:14 PM